Diego Cespedes Diego Cespedes - 20 days ago 22
PHP Question

Laravel 5.2 - Method links does not exist

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>

Answer

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() after paginate().

Comments