问题
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