简体   繁体   中英

Laravel query select single column with multiple value matches

Laravel query select single column with multiple value matches

$user = User::where('name', [
        'User1',
        'User2',
        'User3',
    ])->get();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM