Laravel 5.2-方法链接不存在 [英] Laravel 5.2 - Method links does not exist
本文介绍了Laravel 5.2-方法链接不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将数组$ posts传递给我的视图,并且尝试使用分页,但是我遇到了错误:
i'm passing my array $posts to my view and i'm tryng use pagination but i have the error:
方法链接不存在. (看法: C:\ xampp \ htdocs \ app \ resources \ views \ search.blade.php)
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()
.
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()
.
这篇关于Laravel 5.2-方法链接不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文