Laravel5如何向闭合函数内传递参数 where function 传参
如上,怎么将$title 像$query一样,在函数内部使用?
$result = UserMenus::with(['menu'=>function($query){ $query->where('title',$title); }])->where('user_id',$userId)->first();
解决:
$result = UserMenus::with(['menu'=>function($query) use ($title){ $query->where('title',$title); }])->where('user_id',$userId)->first();
或者
$result = UserMenus::with(function($query) use ($title){
$query->where('title',$title);
})->where('user_id',$userId)->first();