How to Create Multiple Where Clause Query Using Laravel Eloquent?

前端 未结 24 1103
一整个雨季
一整个雨季 2020-11-22 14:30

I\'m using the Laravel Eloquent query builder and I have a query where I want a WHERE clause on multiple conditions. It works, but it\'s not elegant.

E

24条回答
  •  粉色の甜心
    2020-11-22 15:08

    The whereColumn method can be passed an array of multiple conditions. These conditions will be joined using the and operator.

    Example:

    $users = DB::table('users')
                ->whereColumn([
                    ['first_name', '=', 'last_name'],
                    ['updated_at', '>', 'created_at']
                ])->get();
    
    $users = User::whereColumn([
                    ['first_name', '=', 'last_name'],
                    ['updated_at', '>', 'created_at']
                ])->get();
    

    For more information check this section of the documentation https://laravel.com/docs/5.4/queries#where-clauses

提交回复
热议问题