模型::query () 只能使用一次吗?
现在的问题是
public function getPost()
{
return Post::query()
}
public function index()
{
$post = $this->getPost();
return view('index', [
'post' => $post
]);
}
然后我在模板中想使用它们。
index.blade.php
@foreach($post->where('category_id',2)->get() as xxx){...}
结果显示成功
当再次使用这个变量$post,且category_id不为2的时候
@foreach($post->where('category_id',3)->get() as xxx){...}
调用不出来数据了。这是为什么,应该怎么解决?
(clone $post)->where(xxxxxxxxx)