I have a model items. Items hasMany templateItems. The relationship uses items.id as the foreign key in template_items.
I am trying to return all items but only include the related templateItems where template_items.template equals a $id.
I have tried this;
$items = Item::with('templateItems', function($query) use ($id) {
$query->where('template_items.template', $id);
})->get();
I get:
ErrorException in Builder.php line 1150: explode() expects parameter 2 to be string, object given
What am I missing or is there a better way? Thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire