fbpx

Pembuat Website Murah  | servis membuat laman web business  laman web e-dagang, rekawebs Pereka Laman Web, Website Ecommerce Murah, Dapatkan pakej web design serendah RM350 Pelbagai Jenis, .Booking Website, Corporate Website dengan Mobile Responsive.

MENU

Cipta Multiple Where Clause Query Using Laravel Eloquent?

Cara Array list

$query->where([
    ['column_1', '=', 'value_1'],
    ['column_2', '<>', 'value_2'],
    [COLUMN, OPERATOR, VALUE],
    ...
])

sample:

$users = User::where([
       'column1' => value1,
       'column2' => value2,
       'column3' => value3
])->get();
$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();

 

Menggunakan fungsi Antonymous 

$users = User::where('column1', '=', value1)
               ->where(function($query) use ($variable1,$variable2){
                    $query->where('column2','=',$variable1)
                   ->orWhere('column3','=',$variable2);
               })
              ->where(function($query2) use ($variable1,$variable2){
                    $query2->where('column4','=',$variable1)
                   ->where('column5','=',$variable2);
              })->get();
No votes yet.
Please wait...

Leave a Reply

Your email address will not be published. Required fields are marked *