我正在将我的数组 $posts 传递到我的 View ,我正在尝试使用分页,但出现错误:
Method links does not exist. (View: C:\xampp\htdocs\app\resources\views\search.blade.php)
Controller
$posts = Post::where('visible', 1)
->where('expire_date', '>', $current)->where('delete', 0);
$posts->paginate(1);
$posts = $posts->get();
return view('search', compact('posts'));
查看
<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);
。此外,您不应在 paginate()
之后使用 get()
或 all()
。
关于php - Laravel 5.2 - 方法链接不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40575314/