php – Laravel 5.2 – 方法链接不存在

前端之家收集整理的这篇文章主要介绍了php – Laravel 5.2 – 方法链接不存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我将我的数组$帖子传递给我的视图,我尝试使用分页,但我有错误

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

猜你在找的Laravel相关文章