如果你想要得到的結果與你的所有選項,你可以做後續的合併(與union
方法,你可以合併多個查詢):
If ($type!=null && $Des!=null && $cou!=null){
$query1 = Activity::where('id', $type);
$query2 = Activity::where('des_id', $Des);
$query3 = Activity::where('des_id', $cou);
$allQueries = $query1->union($query2)->union($query3)->get();
} elseif ($type!=null && $Des!=null){
$query1 = Activity::where('id', $type);
$query2 = Activity::where('des_id', $Des);
$allQueries = $query1->union($query2)->get();
} elseif ($type!=null && $cou!=null){
$query1 = Activity::where('id', $type);
$query2 = Activity::where('des_id', $cou);
$allQueries = $query1->union($query2)->get();
} elseif ($type!=null && $cou!=null){
$query1 = Activity::where('id', $type);
$query2 = Activity::where('des_id', $Des);
$allQueries = $query1->union($query2)->get();
} elseif ($Des!=null && $cou!=null){
$query1 = Activity::where('id', $cou);
$query2 = Activity::where('des_id', $Des);
$allQueries = $query1->union($query2)->get();
} elseif ($type!=null){
$query1 = Activity::where('id', $type)->get();
} elseif ($Des!=null){
$query1 = Activity::where('id', $Des)->get();
} elseif ($cou!=null){
$query1 = Activity::where('id', $cou)->get();
}
我需要爲我的職務view.So它查詢每個if都需要查詢。 – user3142452
它拋出任何錯誤? – Laerte
不,但查詢連接,並給我結合我想要的是每個查詢結果可能是另一種方式比如果 – user3142452