$p = Product::whereNull("sold_to_user")
->where(function ($q) use ($university) {
$q ->whereNull("target_university")
->orWhere("target_university", $university->id);
})->whereIn("user_id", $userArray)->get();
Jun 26, 2017
3
Level 1
laravel conditional nested query
I have a table name product having column name taraget_university. I need query somethings like
Product::where("sold_to_user",null)
if target_university == null then continue
if target_university !=null then query->where("target_university",$university -> id) ======================================= ->whereIn("user_id",$userArray) ->get();
How to add those conditional query ??
Level 24
Please or to participate in this conversation.