dilfdo
260
2
Laravel

Laravel where clause help

Posted 3 years ago by dilfdo

i wnat to perform search function with laravel for following scenario,

user can select 4 types , each type can contain value 1,2,3

if user select '1' as value for any type , On sql where clause i want to put "==", all the other values i want to put where clause with ">="

ex:
if user enters valuse $type1 = 2 , $type2 = 1 , $type3 = 1, $type4 = 3

$type1 = $request->type1;
$type2 = $request->type2;
$type3 = $request->type3;
$type4 = $request->type4;


$min = '=';
$max = '>=';

how can i make my sql query in following way according to the values enter... pls advice

$fod = FodMap::select('*')

 ->where('type1',$max,$type1)
 ->where('type2',$min,$type2)
 ->where('type3',$min,$type3)
 ->where('type4',$max,$type4)
 ->get();

Please sign in or create an account to participate in this conversation.