Reputation: 43
Laravel query select single column with multiple value matches
$user = User::where('name', [
'User1',
'User2',
'User3',
])->get();
Upvotes: 0
Views: 3413
Reputation: 29258
You're looking for whereIn()
:
$user = User::whereIn('name', ['User1', 'User2', 'User3'])->get();
where()
is used for single values, but whereIn()
uses an array to match against the given column.
Check https://laravel.com/docs/5.8/queries#where-clauses for full details.
Upvotes: 6