Created
June 11, 2021 17:02
-
-
Save owenconti/9a1c5e33d761b14985b63037444d415f to your computer and use it in GitHub Desktop.
whereHasAll functionality in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$authorIds = [1, 2]; | |
Post::whereHas('authors', function ($query, $authorIds) { | |
$query->whereIn('id', $authorIds); | |
}, '=', count($authorIds))->get(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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