Flarum\Core\Discussion::mergePost PHP Method

mergePost() public method

The merge logic is delegated to the new post. (As an example, a DiscussionRenamedPost will merge if adjacent to another DiscussionRenamedPost, and delete if the title has been reverted completely.)
public mergePost ( Flarum\Core\Post\MergeableInterface $post ) : Post
$post Flarum\Core\Post\MergeableInterface The post to save.
return Post The resulting post. It may or may not be the same post as was originally intended to be saved. It also may not exist, if the merge logic resulted in deletion.
    public function mergePost(MergeableInterface $post)
    {
        $lastPost = $this->posts()->latest('time')->first();
        $post = $post->saveAfter($lastPost);
        return $this->modifiedPosts[] = $post;
    }

Usage Example

 /**
  * @param Discussion $discussion
  * @param User $user
  * @param $isLocked
  */
 protected function lockedChanged(Discussion $discussion, User $user, $isLocked)
 {
     $post = DiscussionLockedPost::reply($discussion->id, $user->id, $isLocked);
     $post = $discussion->mergePost($post);
     if ($discussion->start_user_id !== $user->id) {
         $notification = new DiscussionLockedBlueprint($post);
         $this->notifications->sync($notification, $post->exists ? [$discussion->startUser] : []);
     }
 }
All Usage Examples Of Flarum\Core\Discussion::mergePost