mysql - Laravel doesnthave() 生成一个查询,不会转义 \
问题描述
我有一个users
表,它与businesses
表有关系,我想要的是搜索还没有业务但他们的角色是business
(尚未创建业务资料的用户)的用户。\
以下是我的查询,但是在查询 where 子句中转义时出现了一个奇怪的问题。
$user = User::client()->latest()->search()->doesntHave('business')->select(DB::raw("CONCAT('first_name', ' ', 'last_name') AS name"),'id')->get();
以下是我的用户模型功能。
public function scopeClients($query)
{
return $query->role('Business');
}
public function scopeSearch($query)
{
foreach (request()->all() as $key => $value) {
if ($key == 'full_name') {
$query->whereRaw("UPPER(CONCAT(`first_name`, ' ', `last_name`)) LIKE ?", ['%' . strtoupper($value) . '%']);
}
}
return $query;
}
但它生成的查询是这样的:
select CONCAT('first_name', ' ', 'last_name') AS name, `id`
from `users` where exists (select * from `roles` inner join `model_has_roles` on `roles`.`id` = `model_has_roles`.`role_id`
where `users`.`id` = `model_has_roles`.`model_id` and `model_has_roles`.`model_type` = 'App\User' and (`roles`.`id` = 2)) and not exists (
select * from `businesses` where `users`.`id` = `businesses`.`owner_id` and `businesses`.`deleted_at` is null
) and UPPER(CONCAT(`first_name`, ' ', `last_name`)) LIKE '%AHMAD%' order by `created_at` desc
在上面的查询中,唯一的问题是\
在App\User
字符串中转义
解决方案
推荐阅读
- angular - 如何在Angular中的ag-grid中给出单元格中的链接与其他单元格值?
- apache-spark - 如何解决此类错误“显示不是会员”
- android - 我想在 android 中上传之前压缩图像,它适用于画廊图像但不适用于相机图像
- jquery - 页面加载后图像缩放工作,更改图库后图像缩放不起作用
- php - 回显 LEFT() 查询
- reactjs - 访问父组件中的表单(react-final-form)状态
- c# - 锁定 Semaphore 对象是否有意义?
- google-bigquery - 数据集与架构定义
- javascript - 带可折叠标题的角材料表
- c# - 损坏的身份验证和会话管理