The following obviously results in undefined variable.
public function show($locale, $slug)
{
$article = Article::whereHas('translations', function ($query) {
$query->where('locale', 'en')
->where('slug', $slug);
})->first();
return $article;
}
Trying to supply the function with the $slug variable:
public function show($locale, $slug)
{
$article = Article::whereHas('translations', function ($query, $slug) {
$query->where('locale', 'en')
->where('slug', $slug);
})->first();
return $article;
}
results in
Missing argument 2 for App\Http\Controllers\ArticlesController::App\Http\Controllers\{closure}()
how can you allow the funtion to have access to $slug?