【发布时间】:2018-09-07 12:51:21
【问题描述】:
这可能是一个 SQL 限制,但我正在处理一个 Laravel 项目,所以我提出问题来解决我想要完成的任务。
我正在搜索模型(及其关系)
Auth::user()->employers()
->where('name', 'like' $filter)
->orWhereHas('locations.location', function($query) use ($filter) {
$query->where('name', 'like', $filter);
})
->orWhereHas('locations.branches', function($query) use ($filter) {
$query->where('name', 'like', $filter);
})
->orWhereHas('locations.positions', function($query) use ($filter) {
$query->where('name', 'like', $filter);
})->get();
我希望能够确定哪些条件与记录匹配,以便我可以告诉前端,“嘿,这条记录正在显示给您,因为其中嵌套的 x 属性与您的搜索条件匹配。 "其中 x 是使其匹配的条件。
上面的代码返回匹配的记录集合。 我想知道这些记录中的每一个在哪里匹配。
【问题讨论】:
-
我不明白这个问题
-
好的,我想根据各种搜索条件进行搜索,它们都是可选的(WHERE location.name = 'Peter' OR 'location.branches' = 'Peter' OR 'location. cmets' = '彼得')。所以我想显示哪个搜索条件与我的数据库中的记录匹配。这有意义吗?
-
那么你想要它怎么样?作为一个单独的列?
-
我现在并不在乎,我主要是想尽一切办法做到这一点。