mysql - Eloquent (Laravel) query in many to many relation -
i have many many relation(eloquent laravel) , want filter item tags.
table_item table_item_tag table_tag id name id item_id tag_id id name 1 item 1 1 1 1 tag 2 item b 2 1 2 2 tag b 3 2 1
filter result should this: `
filter: name:tag a&b : sum of item 1 name:tag : sum of item 1
any ideas on how query should like? ive been struggling sum of items have both tags
assuming eloquent relations set properly, want along these lines:
$tags = ['tag a', 'tag b']; // or input or wherever item::wherehas('tags', function ($q) use ($tags) { foreach ($tags $tag) { $q = $q->where('name', $tag); } })->get();
Comments
Post a Comment