【发布时间】:2020-11-12 16:07:08
【问题描述】:
Laravel 版本:7.0
$posts = Post::where("status", 1)->get();
Above 返回所有已批准的帖子。
$top_featured_posts = Post::where("status", 1)->orderBy("featured", "DESC")->take(4);
以上将获得 4 个按特色排序的帖子。
$top_recent_posts = Post::where("status", 1)->latest()->take(4);
以上将获得 4 个由 created_at 订购的帖子。 ...
我怎样才能只用一个查询得到它们?
我想得到如下结果来使用它们。
$top_featured_posts[0], $top_featured_posts[1], $top_featured_posts[2], $top_featured_posts[3]
$top_recent_posts[0], $top_recent_posts[1], $top_recent_posts[2], $top_recent_posts[3]
谁能帮助我?谢谢
【问题讨论】:
标签: php laravel eloquent laravel-query-builder laravel-collection