【发布时间】:2018-04-16 01:01:23
【问题描述】:
我正在尝试在 laravel 中制作过滤器。以下过滤器有效
$posts= Post::where('category',$request->category)->orderBy('id','desc')->paginate(10);
但是当我尝试做这样的事情时
public function index(Request $request)
{
$posts= Post::where('category',$request->category)->get();
$posts->latest()->paginate(10);
dd($posts);
它不起作用。有人可以解释为什么会这样,并为我提供有效的代码。我的项目有多个过滤器。
【问题讨论】:
-
这是什么 laravel 版本?以及“它不起作用”是什么意思,即您看到了什么错误?
-
这是 laravel 5.5,我的意思是较低的代码不起作用
-
你遇到了什么错误?
-
$blogs = Blog::where('category',$request->category)->get(); $blogs->latest()->分页(10); dd($博客);这段代码给我 if (!static::hasMacro($method)) { throw new BadMethodCallException("Method {$method} 不存在。"); } 和 Method latest not found
-
当你运行第二个代码时,你得到了什么错误。您可以使用您遇到的错误更新您的问题。这样可以避免您得到随机或猜测的问题答案。
标签: php laravel collections filter eloquent