遇到一個情況,要用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

 

arrow
arrow
    全站熱搜

    dizzy03 發表在 痞客邦 留言(0) 人氣()