如何在Laravel 5.3中将变量传递给内部函数?
问题描述:
我想通过语言环境数据到雄辩的查询,但它不能得到它。 $locale
值取自URI。如何在Laravel 5.3中将变量传递给内部函数?
class MyController extends Controller
{
public function index($locale = 'en')
{
$news = News::join('categories', 'categories.id', '=', 'news.catid')
->select('news.*', 'categories.category')
->where([['news.published', '1'], ['news.deleted', '0']])
->where(function ($query) {
$query->where('news.language', $locale) //$locale is not recognized naturally
->orWhere('news.language', 'all');
})
->orderBy('news.published_at', 'desc')
->take(4)
->get();
.
.
.
}
}
如何传递$locale
值到子查询?
'function($ query)use($ locale){' – Clive