I want to list all campaigns with their relations from database. Here is the code for now.
Campaign.php
public function task(){
return $this->hasMany('Task','campaign_id');
}
}
?>
Task.php
public function campaign(){
return $this->belongsTo('Campaign','campaign_id');
}
}
?>
And Page controller
public function campaigns(){
return View::make('pages.platform.campaigns')
->with('campaigns', Campaign::all());
}
It this case when I do this:
<pre>
@foreach($campaigns as $c)
<? print_r($c) ?>
@endforeach
</pre>
I can't see the relations
[relations:protected] => Array()
How can I access this related models so I can echo them like
$c['name'] // Name field in Campaign table
$c['task']['name'] // Name field in related Task table