我将数组 $posts 传递到我的视图,我尝试使用分页,但出现错误:
方法链接不存在。 (看法:
C:\xampp\htdocs\app\resources\views\search.blade.php)
控制器
$posts = Post::where('visible', 1)
->where('expire_date', '>', $current)->where('delete', 0);
$posts->paginate(1);
$posts = $posts->get();
return view('search', compact('posts'));
VIEW
<div class="pagination-bar text-center">
{{ $posts->links() }}
</div>
将您的代码更改为:
$posts = Post::where('visible', 1)
->where('expire_date', '>', $current)
->where('delete', 0)
->paginate(1);
return view('search', compact('posts'));
您的代码不起作用,因为您没有保存paginate()
结果为变量,例如$posts = $posts->paginate(1);
。另外,你不应该使用get()
or all()
after paginate()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)