Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save owenconti/9a1c5e33d761b14985b63037444d415f to your computer and use it in GitHub Desktop.
Save owenconti/9a1c5e33d761b14985b63037444d415f to your computer and use it in GitHub Desktop.
whereHasAll functionality in Laravel
$authorIds = [1, 2];
Post::whereHas('authors', function ($query, $authorIds) {
$query->whereIn('id', $authorIds);
}, '=', count($authorIds))->get();
$authorIds = [1, 2];
Post::whereHas('authors', function ($query, $authorIds) {
$query->whereIn('id', $authorIds);
})->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment