我查询了 Category 模型以获取用于查询 Post 模型的所有 id 'name', '=', $name,但出现错误。
public function getList($name)
{
$category_id = Category::where('name', '=', $name)->first()->id;
$posts = Post::whereHas('category', function ($q) use ($category_id) {
$q->where('id', '=', $category_id);
})->paginate(12);
return view('blog.index')->withPosts($posts)->withName($name);
}
Run Code Online (Sandbox Code Playgroud)
这是我的错误。
Builder.php 第 877 行中的 ErrorException:compact():未定义的变量:运算符