Laravel 5.2 - Method links does not exist

浪子不回头ぞ 提交于 2020-01-14 19:37:25

问题


i'm passing my array $posts to my view and i'm tryng use pagination but i have the error:

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'));

VIEW

<div class="pagination-bar text-center">
       {{ $posts->links() }}
</div>

回答1:


Change you code to this:

$posts = Post::where('visible', 1)
             ->where('expire_date', '>', $current)
             ->where('delete', 0)
             ->paginate(1);

return view('search', compact('posts'));

Your code doesn't work because you do not save paginate() results to a variable, like $posts = $posts->paginate(1);. Also, you shouldn't use get() or all() after paginate().



来源:https://stackoverflow.com/questions/40575314/laravel-5-2-method-links-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!