遇到一個情況,要用if else做不同的where查詢。
平常SQL指令都是一行到底,要怎麼分段寫呢?
重點是: $query = $query->where('self', '<>', true);
不是直接用$query->where('self', '<>', true);
EX:
$query = SocialMediaFeed::where('location_id', $location_id);
if(!$filters) {
$query = $query->where('self', '<>', true);
} else {
$query = $query->orWhere('self', true);
}
--
https://stackoverflow.com/questions/45585657/laravel-where-with-if-else
全站熱搜