Laravel 5.5 &引用;其中;在雄辩的查询中,连接了3个表
我有三个表,我已经使用eloquent连接了它们,查询如下Laravel 5.5 &引用;其中;在雄辩的查询中,连接了3个表,laravel-5.5,Laravel 5.5,我有三个表,我已经使用eloquent连接了它们,查询如下 $truck = TCategory::with('truck_categories.touch_points')->get(); if(count($truck) > 0) { return response()->json(array('result' => $truck)); } else { return response()->json(
$truck = TCategory::with('truck_categories.touch_points')->get();
if(count($truck) > 0) {
return response()->json(array('result' => $truck));
} else {
return response()->json(array('result' => 'No Trucks.'));
}
答案是:
{
"result": [{
"id": 6,
"name": "western",
"created_at": null,
"updated_at": null,
"truck_categories": [{
"id": 9,
"touch_point_id": 8,
"t_category_id": 6,
"created_at": null,
"updated_at": null,
"touch_points": {
"id": 8,
"brand_id": 1,
"user_id": 11,
"base_latitude": 3.104193,
"base_longitude": 101.610487,
"name": "testing ok",
"approved": 1,
"driver": null,
"created_at": "2018-04-25 07:43:49",
"updated_at": "2018-04-25 07:45:27",
"menu_id": 1,
"location": "Kelana Jaya, 47300 Petaling Jaya, Selangor, Malaysia",
"service_on_off": 1,
"slug": "testing-ok",
"image": null,
"position": {
"lat": 3.104193,
"lng": 101.610487
}
}
}]
}, ...
触摸点出现在卡车类别中,我想在查询中输入where条件,有人能帮我吗?。提前感谢。您可以将以下条件放在哪里:
$truck = TCategory::with(['truck_categories.touch_points' => function($query){
$query->where('<Put your condition here>');
}])->get();
if(count($truck) > 0) {
return response()->json(array('result' => $truck));
} else {
return response()->json(array('result' => 'No Trucks.'));
}
$truck=TCategory::with(['truck\u categories.touch\u points'=>函数($query){
$query->where(“”);
}])->get();
如果(计数($truck)>0){
return response()->json(数组('result'=>$truck));
}否则{
return response()->json(数组('result'=>'No Trucks');
}
请检查我下面的答案。感谢您的回复,我使用了它并得到了这个错误mb_strpos()希望参数1是字符串,对象给定查询:$truck=TCategory::with('truck_categories.touch_points',function($query){$query->where('name',testing ok');})->get();“where”适用于哪个表?