Laravel 5.2 - 方法链接不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40575314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.2 - Method links does not exist
提问by Diego Cespedes
i'm passing my array $posts to my view and i'm tryng use pagination but i have the error:
我正在将数组 $posts 传递给我的视图,并且我正在尝试使用分页,但出现错误:
Method links does not exist. (View: C:\xampp\htdocs\app\resources\views\search.blade.php)
方法链接不存在。(查看: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>
回答by Alexey Mezenin
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()
.
您的代码不起作用,因为您没有将paginate()
结果保存到变量中,例如$posts = $posts->paginate(1);
. 此外,您不应该使用get()
或all()
之后paginate()
。