我尝试编写搜索代码,这是我的代码:
$services = Service::query()->with('plans')->latest(); if ($request->service_name) { $services = $services->whereRaw("CONVERT(JSON_EXTRACT(name, '$.ar') using 'utf8') LIKE '%$request->service_name%' ") ->orWhereRaw("CONVERT(JSON_EXTRACT(name, '$.en') using 'utf8') LIKE '%$request->service_name%' ") ->orWhereRaw("CONVERT(JSON_EXTRACT(name, '$.he') using 'utf8') LIKE '%$request->service_name%' "); } if ($request->plan_name) { $plan_name = $request->plan_name; $services = $services->whereHas('plans', function ($q) use ($plan_name) { $q->where('name->en','Like','%'.$plan_name.'%'); }); } return $services->get();
但是当我在请求中发送 plan_name 时,代码按服务名称而不是计划名称进行过滤
我尝试过何时在请求中发送计划名称代码按计划名称过滤数据,但它不起作用