Home > database >  laravel eloquent where and multiple or where
laravel eloquent where and multiple or where

Time:12-06

I'm using the Laravel Eloquent query builder and i want to have advance queries inside when clause

my eloquent :

bank::where('shop_id', $shopId)
            ->when(($search != ""), function ($query) use ($search) {
                return $query->orWhere('bank_name', 'like', '%'.$search.'%')
                        ->orWhere('account_name', 'like', '%'.$search.'%')
                        ->orWhere('account_number', 'like', '%'.$search.'%');
            })->toSql();

sql from eloquent :

select * from bank 
where shop_id = 1 
and bank_name like '           
  • Related