Laravel5如何向闭合函数内传递参数
程序员文章站
2022-06-17 08:42:21
...
如上,怎么将$title 像$query一样,在函数内部使用?
$result = UserMenus::with(['menu'=>function($query){
$query->where('title',$title);
}])->where('user_id',$userId)->first();
$result = UserMenus::with(['menu'=>function($query){
$query->where('title',$title);
}])->where('user_id',$userId)->first();
回复内容:
如上,怎么将$title 像$query一样,在函数内部使用?
$result = UserMenus::with(['menu'=>function($query){
$query->where('title',$title);
}])->where('user_id',$userId)->first();
php
$result = UserMenus::with(['menu'=>function($query) use($title){ $query->where('title',$title); }])->where('user_id',$userId)->first();
$result = UserMenus::with(
[
'menu'=>function($query){
global $title;
$query->where('title',$title);
}
])->where('user_id',$userId)->first();
话说PHP 有全局函数,你加global 不行吗?
推荐阅读