jeudi 27 octobre 2016

How do I do a conditional join or with? Laravel 5

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.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fbdOIU
via IFTTT

Aucun commentaire:

Enregistrer un commentaire