我正在尝试在Laravel中编写这个MySQL查询:
- name: copy
shell: cp /home/user/test1.txt /home/user/Desktop/test1.txt
我们的想法是返回SELECT * FROM users WHERE CONCAT(firstName, ' ', lastName) LIKE '%John%'
或firstName
lastName
的记录
我尝试过的事情:
John
错误 $users = User::whereRaw("(CONCAT(users.firstName, ' ', users.lastName) like '%John%')");
The Response content must be a string or object implementing __toString(), "boolean" given.
返回$users = User::whereRaw("(CONCAT(users.firstName, ' ', users.lastName) like '%?%')",[$search])->get();
[]
返回$users = User::whereRaw("(CONCAT(users.firstName, ' ', users.lastName) like ?)",[$search])->get();
答案 0 :(得分:0)
检查SQL之后(感谢@xAoc!)我发现生成的SQL错误。
这似乎生成了正确的SQL:
return User::whereRaw("(CONCAT(users.firstName, ' ', users.lastName) like '%$search%')")->get();
答案 1 :(得分:0)
对我来说,你可以试试这个:
$search = 'John Smith';
$users = User::whereRaw("(CONCAT(first_name, ' ', last_name) like '%$search%')")->get();
输出如下:
收藏{#573▼ #items:array:13 [▶] }