$modelBanner = Banner::whereRaw("delete_flag= 0 AND visible= '0'")->get()
Output:
select * from `banners` where delete_flag= 0 AND visible= '0'
$modelBanner = Banner::where(function ($query) {
$query->where(['delete_flag' => 0, 'visible' => 0]);
})->get();
Output:
select * from `banners` where ((`delete_flag` = ? and `visible` = ?))
$modelBanner = Banner::where(function ($query) {
$query->where(['delete_flag' => 0])
->orWhere(['visible' => 0]);
})->get();
Output:
select * from `banners` where ((`delete_flag` = ?) or (`visible` = ?))
$modelBanner = Banner::where(function ($query) {
$query->where(['delete_flag' => 0, 'visible' => 0])
->where(function($sql){
$sql->where('delete_flag' , 0);
$sql->where('visible' , 0);
});
})->get();
Output:
select * from `banners` where ((`delete_flag` = ? and `visible` = ?) and (`delete_flag` = ? and `visible` = ?))
Output:
select * from `banners` where delete_flag= 0 AND visible= '0'
$modelBanner = Banner::where(function ($query) {
$query->where(['delete_flag' => 0, 'visible' => 0]);
})->get();
Output:
select * from `banners` where ((`delete_flag` = ? and `visible` = ?))
$modelBanner = Banner::where(function ($query) {
$query->where(['delete_flag' => 0])
->orWhere(['visible' => 0]);
})->get();
Output:
select * from `banners` where ((`delete_flag` = ?) or (`visible` = ?))
$modelBanner = Banner::where(function ($query) {
$query->where(['delete_flag' => 0, 'visible' => 0])
->where(function($sql){
$sql->where('delete_flag' , 0);
$sql->where('visible' , 0);
});
})->get();
Output:
select * from `banners` where ((`delete_flag` = ? and `visible` = ?) and (`delete_flag` = ? and `visible` = ?))
Source:
https://old-oomusou.goodjack.tw/laravel/where-and-or/
https://laravel-news.com/eloquent-tips-tricks
https://fkrihnif.medium.com/mastering-laravel-eloquent-tips-and-tricks-for-effortless-database-interactions-542e64ffbb0
0 comments:
Post a Comment