Performing concat on where clause

Posted 3 years ago by developerchick

I have a question, how do you go about using the where clause and performing concatenation. MySQL query: select * from users where concat(name, ' ', surname) LIKE '%John%' (using this as an example because if someone puts in "John Robinson" in the search box, we want them to see just that result. The query works fine in MySQL but I am having a hard time doing this in Laravel in the where statement. Part of my original statement that I am modifying received from different devs:

])->where ('name', 'LIKE', '%' . $keyword . '%') ->orWhere('surname', 'LIKE', '%' . $keyword . '%') ->get();

This gives us all Johns but if someone puts in John Robinson, it gives us only people with the last name Robinson. I am a noob and sorry if this is a stupid question.

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