Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

try

Page::with('Section')->where(...)->get()
Last updated 2 years ago.
0

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 luck
Last updated 2 years ago.
0

use:

with('sections')
Last updated 2 years ago.
0
with('section')
Last updated 2 years ago.
0

Thanks 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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.