为什么从控制器调用 model 的时候 不能先调用 where 语句?
public function show(Category $category, Topic $topic)
{
$order = request('order');
$topics = Topic::where('category_id', $category->id)
->withOrder($order)
->paginate(20);
return view('topics.index', compact('topics', 'category'));
}
为什么这里如果先调用where语句的话 查出来就是所有的分类数据
如果我改成Topic::withOrder($order)->where('category_id', $category->id) ....
就可以正常返回某个分类下的数据
推荐文章: