Php Laravel在我的搜索系统请求中雄辩地使用了orWhere查询
我试图用搜索系统编码一个请求。代码如下:Php Laravel在我的搜索系统请求中雄辩地使用了orWhere查询,php,laravel,search,eloquent,laravel-query-builder,Php,Laravel,Search,Eloquent,Laravel Query Builder,我试图用搜索系统编码一个请求。代码如下: $search=request()->get('search'); if(Auth::user()->hasRole('admin')| | true) { list($orderBy,$orderDirection)=分解('.',请求()->get('sort_by'); $prestations=Prestation::with( '服务:id,名称', '设施:id,名称' ) ->orWhere('service:name','regexp',
$search=request()->get('search');
if(Auth::user()->hasRole('admin')| | true)
{
list($orderBy,$orderDirection)=分解('.',请求()->get('sort_by');
$prestations=Prestation::with(
'服务:id,名称',
'设施:id,名称'
)
->orWhere('service:name','regexp',“/$search/i”)
->orderBy($orderBy,$orderDirection)
->单帕吉纳(50);
$res=[
“结果”=>$prestations,
“总计”=>Prestation::all()->count(),
];
返回$res;
}
问题是我不知道如何做一些事情,比如我尝试使用或从何处
->获取所有服务名称(从“与”的关系中),这些名称等于我的$search
多谢各位 试试这个查询
$prestations = Prestation::with(
[
'service' => function($service) use($search){
$service->select(['id','name'])->where('name', $search);
},
'facility' => function($facility) {
$facility->select(['id','name'])
}
]
);
$prestations=Prestation::with('service:id,name','facility:id,name')的含义是什么?
我想非常详细地了解这一点。任何人请帮助我。Prestation::with('service:id,name','facility:id,name')
。。。service:id,name
@VikasKatariya的含义是关于关系的,我的表Prestations有外键service和Facility,因此我可以在outputhello prashant中使用“with”获取数据。你能解释一下Prestation::with('service:id,name','Facility:id,name')的含义吗
?因为我不知道。@VikasKatariya它的意思是只从关系中加载给定的列。从服务
仅获取id
和名称
。我尝试了示例,但对我无效。请发送示例或教程参考链接?@PrashantDeshmukh。。。。。这很有效!但我有一个小问题:我只获取设施数据,但服务在output@VikasKatariya