Issue
I have two columns in the users
table: first_name
& last_name
. I want to query the user search john doe
. I attempted it like the following.
$users = User::where('username', $request->text)
->orWhere('first_name', 'LIKE', '%'.$request->text.'%')
->paginate(5);
It searches only through john
and I don't understand how to make it work
Solution
Try the following...
$users = User::where('username', $request->text)
->orWhereRaw("CONCAT(first_name, ' ', last_name)
LIKE ?", ['%' . $request->text . '%'])
->paginate(5);
The whereRaw
and orWhereRaw
methods can be used to inject a raw where clause into your query.
Answered By - Karl Hill
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.