mirror of
https://github.com/flarum/framework.git
synced 2024-12-05 00:43:39 +08:00
Use Eloquent's latest
and oldest
This commit is contained in:
parent
a7a0a2ca86
commit
9ca95afafe
|
@ -64,7 +64,7 @@ class UpdateDiscussionController extends AbstractShowController
|
||||||
|
|
||||||
if ($posts = $discussion->getModifiedPosts()) {
|
if ($posts = $discussion->getModifiedPosts()) {
|
||||||
$posts = (new Collection($posts))->load('discussion', 'user');
|
$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 ($discussionPosts as &$id) {
|
||||||
foreach ($posts as $post) {
|
foreach ($posts as $post) {
|
||||||
|
|
|
@ -223,7 +223,7 @@ class Discussion extends AbstractModel
|
||||||
public function refreshLastPost()
|
public function refreshLastPost()
|
||||||
{
|
{
|
||||||
/** @var Post $lastPost */
|
/** @var Post $lastPost */
|
||||||
if ($lastPost = $this->comments()->latest('created_at')->first()) {
|
if ($lastPost = $this->comments()->latest()->first()) {
|
||||||
$this->setLastPost($lastPost);
|
$this->setLastPost($lastPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ class Discussion extends AbstractModel
|
||||||
*/
|
*/
|
||||||
public function mergePost(MergeableInterface $post)
|
public function mergePost(MergeableInterface $post)
|
||||||
{
|
{
|
||||||
$lastPost = $this->posts()->latest('created_at')->first();
|
$lastPost = $this->posts()->latest()->first();
|
||||||
|
|
||||||
$post = $post->saveAfter($lastPost);
|
$post = $post->saveAfter($lastPost);
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class NotificationRepository
|
||||||
return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count'))
|
return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count'))
|
||||||
->mergeBindings($primaries->getQuery())
|
->mergeBindings($primaries->getQuery())
|
||||||
->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id'))
|
->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id'))
|
||||||
->latest('created_at')
|
->latest()
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user