Laravel 5.2 - 方法链接不存在

Laravel 5.2 - Method links does not exist

我正在将我的数组 $posts 传递到我的视图,我正在尝试使用分页,但出现错误:

Method links does not exist. (View: 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);。此外,您不应在 paginate().

之后使用 get()all()