Published under Laravel.
By default, a
whereHas query checks to see that the given relation has at least one row for the given constraint, ie:
The above query will return posts that were authored by authors with ID 1 or 2. If, however, we want to find the posts that were authored by both authors 1 and 2, we need to change the query to tell Laravel to include posts that return 2 author relation rows when filtered:
The above query tells Laravel to load the posts that have 2 author relation records when the author relation records are filtered by the given array of IDs.