Forum

eager loading question / issue ?

I've got this :

        $location = \App\Location::find($location_id)->with('items','items.vendors')->get();

but its not using the find($location_id) and its returning all locations collections in the database. if I drop everything starting at ->with, it returns just a single location collection.

Am I doing something wrong with the syntax?

rawrkats
rawrkats
  • 1 week ago
jay4yam
Solution

Try :

$location = \App\Location::with('items', 'items.vendor')->findOrFail($location_id);