以下显然会导致未定义的变量.
public function show($locale, $slug)
{
$article = Article::whereHas('translations', function ($query) {
$query->where('locale', 'en')
->where('slug', $slug);
})->first();
return $article;
}
Run Code Online (Sandbox Code Playgroud)
尝试使用$ slug变量提供函数:
public function show($locale, $slug)
{
$article = Article::whereHas('translations', function ($query, $slug) {
$query->where('locale', 'en')
->where('slug', $slug);
})->first();
return $article;
}
Run Code Online (Sandbox Code Playgroud)
结果是
Missing argument 2 for App\Http\Controllers\ArticlesController::App\Http\Controllers\{closure}()
Run Code Online (Sandbox Code Playgroud)
你怎么能让功能访问$ slug?现在这可能很简单但我无法找到我需要搜索的内容.