Say I have 2 models, Category and POI where 1 Category can have many POIs.
$categoryDetails = Category::with([ 'pois' => function ($query) { $query->where('is_poi_enabled', true); }, ])->findOrFail($id); The above query returns results from the specific Category as well as its POIs.
However, with the query below:
$query->select('id', 'name')->where('is_poi_enabled', true); The POIs become empty in the collection.
Any idea why this is happening? When added a select clause to the Eloquent ORM?
pois? Select that foreign key too.