1
我想通過語言環境數據到雄辯的查詢,但它不能得到它。 $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