Support the ongoing development of Laravel.io →
Database Eloquent

i am following this tutorial http://scotch.io/tutorials/php/a-guide-to-using-eloquent-orm-in-laravel#sample-application

On this tutorial below code is use for routing a page with bread model & all the model related to it

// Route::get('eloquent', function() {

	return View::make('eloquent')

		// all the bears (will also return the fish, trees, and picnics that belong to them)
		->with('bears', Bear::all()->with('trees', 'picnics'));

});

but when i run this below error appear

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Call to undefined method Illuminate\Database\Eloquent\Collection::with()"

Stacktrace: #1 Symfony\Component\Debug\Exception\FatalErrorException in J:\server2\htdocs\practice\laravel\app\routes.php:18 #0 Illuminate\Exception\Handler:handleShutdown in <#unknown>:0

Now what should i do ???

Last updated 2 years ago.
0

The "all" function returns a collection, not a query. You need to use something like Bears::with('trees', 'picnics')->get().

Last updated 2 years ago.
0

thanks thepsion5 now it's work

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Mohib1992 mohib1992 Joined 7 Aug 2014

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.

© 2025 Laravel.io - All rights reserved.