0
我需要兩個不同的用戶角色相同的查詢。區別只在於一個whereNotIn
的情況。如何包含或排除在Laravel中的語句雄辯
因此,對於基本的用戶將是:
$chart2 = DB::connection('mysql2')->table('tv')
->select('*')
->join('epgdata_channel', 'cid', '=', 'channelid')
->where('ReferenceDescription', $campaign->spotid)
->whereNotIn('ChannelName', $sky)
->get();
而對於高級:
$chart2 = DB::connection('mysql2')->table('tv')
->select('*')
->join('epgdata_channel', 'cid', '=', 'channelid')
->where('ReferenceDescription', $campaign->spotid)
->get();
我知道我可以用簡單的if語句做到這一點:
if($user->userRole == "Basic"){
//first $chart2
}
else{
//second $chart2}
但我有很多的查詢,我只需要添加或刪除這裏的諾丁條件和重寫查詢(使用如果政治家噸)不是一個很好的解決方案。