I have a collection which I filter by tags. This works really great with the when()
method.
$categories = ['Test1', 'Test2'];
$articles = collection('articles')
->when(!empty($categories), function ($child) use ($categories) {
return $this->filter(function ($child) use ($categories) {
return array_intersect($child->categories()->split(','), $categories);
});
});
This returns all pages with the category Test1
OR Test2
. How can I get only items with both categories included?
I’m just feeling really stupid .
Thanks