Hi I have a situation where I want
$first_name = $request->first_name;
$last_name = $request->last_name;
$customers = Customer::where('first_name','=',$first_name)
->where('last_name','=',$last_name **OR $last_name <> NULL**)
->get();
I want where
clause to be implemented only if the input $last_name
is not blank.
How can I achieve that?
2
Answers
You can use
when()
An example
when
will addwhere
condition when thefirst_name
is notNULL
orfalse
I hope this helps you
You can use :