I have two Models, Company and Jobs. A Company can have many Jobs.
Job Model:
class Job extends \Eloquent {
public function company() {
return $this->belongsTo('Company');
}
}
Company Model:
class Company extends \Eloquent {
public function jobs() {
return $this->hasMany('Job');
}
}
If I do the following, I want the $job
object to have both the job & company objects in the same way I would if I did a SQL join such as:
SELECT * FROM `jobs` JOIN company ON `company_id` = company.id WHERE jobs.`id` = 156;
Instead, if I do this
$job = Job::find($id);
var_dump($job);
exit;
$job
has only the job.
If I do this:
$job = Job::find($id)->company;
var_dump($job);
exit;
I only get the company.
How do I get $job
to be the equivalent of the SQL join?