Use Eloquent's latest and oldest

This commit is contained in:
Toby Zerner 2018-07-21 17:21:08 +09:30
parent a7a0a2ca86
commit 9ca95afafe
3 changed files with 4 additions and 4 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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();
}