try
Page::with('Section')->where(...)->get()
Same error. Call to undefined method Illuminate\Database\Query\Builder::Section()
Controller:
$page = Page::with('Section')->where('slug' , '=', $slug)->get();
var_dump($page);
Models: Page.php
class Page extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'pages';
public function sections()
{
return $this->hasMany('Section');
}
}
Section.php
<?php class Section extends Eloquent { /** * The database table used by the model. * * @var string */ protected $table = 'sections'; public function pages() { return $this->belongsTo('Page'); } } But still no luckThanks guys!
$page = Page::with('sections') ->where('slug', '=', $slug) ->get();
var_dump($page);
die();
Returns a result but the blade throws errors.
Before I added the with->('sections') the blade is a simple:
<h1>{{ $page->slug }}</h1> But how to get the correct data from $page for the Page and the Section to echo it out correct.Thanks again for all your help.
Appreciated greatly.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community