Answer the question
In order to leave comments, you need to log in
Is there an analogue of "where" with multiple fields?
Hello. The question is the following. There is a table with users, by which I am looking for a match of the "Last Name" column with a part of the substring: User::where("surname", "like", "%str%")...
Now there is a need to look for a match of the same substring with several fields, for example, with the first name:
User::where("surname", "like", "%str%")->orWhere("name", "like", "%str%")...
User::where(["surname", "name"], "like", "%str%")...
Answer the question
In order to leave comments, you need to log in
$query= User::query();
foreach (['surname', 'name'] as $item) {
$query->orWhere($item, "like", '%str%');
}
$result = $res->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question