From 9ca95afafeccde42e29a5702f4c23ad8e3bdce4e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:21:08 +0930 Subject: [PATCH] Use Eloquent's `latest` and `oldest` --- .../core/src/Api/Controller/UpdateDiscussionController.php | 2 +- framework/core/src/Discussion/Discussion.php | 4 ++-- framework/core/src/Notification/NotificationRepository.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Api/Controller/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index 86b0f8152..68e196e21 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -64,7 +64,7 @@ class UpdateDiscussionController extends AbstractShowController if ($posts = $discussion->getModifiedPosts()) { $posts = (new Collection($posts))->load('discussion', 'user'); - $discussionPosts = $discussion->posts()->whereVisibleTo($actor)->orderBy('time')->pluck('id')->all(); + $discussionPosts = $discussion->posts()->whereVisibleTo($actor)->oldest()->pluck('id')->all(); foreach ($discussionPosts as &$id) { foreach ($posts as $post) { diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index d9feb4b6c..982bcccb3 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -223,7 +223,7 @@ class Discussion extends AbstractModel public function refreshLastPost() { /** @var Post $lastPost */ - if ($lastPost = $this->comments()->latest('created_at')->first()) { + if ($lastPost = $this->comments()->latest()->first()) { $this->setLastPost($lastPost); } @@ -269,7 +269,7 @@ class Discussion extends AbstractModel */ public function mergePost(MergeableInterface $post) { - $lastPost = $this->posts()->latest('created_at')->first(); + $lastPost = $this->posts()->latest()->first(); $post = $post->saveAfter($lastPost); diff --git a/framework/core/src/Notification/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php index 629fe8792..726206cb3 100644 --- a/framework/core/src/Notification/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -41,7 +41,7 @@ class NotificationRepository return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count')) ->mergeBindings($primaries->getQuery()) ->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id')) - ->latest('created_at') + ->latest() ->get(); }