I am doing a search with eloquent
Laravel, but I had a problem when I had 2 where
and a orWhere
, since in my database we work state [0, 1]
to see if a record has been unsubscribed.
But when looking for a user the following appears:
$users = User::where('code', 'LIKE', '%'.$request->search.'%')
->orWhere('name', 'LIKE', '%'.$request->search.'%')
->where('state', 1)
->get();
I put the where at the end so that it only shows me the users who have not been unsubscribed, but when searching they still continue to show me.
return $users;
[
{
"id": 1,
"code": "USR-001",
"name": "Jhon Smith",
"state": 0
},
{
"id": 2,
"code": "USR-002",
"name": "Carlos Smith",
"state": 1
}
]
What you have to use is a
funcion
to be able to control thewhere
and theorWhere
.Try this: