From ffea0db0126346d3a3468cd266f1f1ece70ffcc1 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Mon, 4 Nov 2024 11:28:57 +0100 Subject: [PATCH] fix(regression): discussion creation fails --- framework/core/src/Api/Resource/DiscussionResource.php | 2 +- framework/core/src/Discussion/Discussion.php | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/framework/core/src/Api/Resource/DiscussionResource.php b/framework/core/src/Api/Resource/DiscussionResource.php index 41c7add9e8..36e740ba23 100644 --- a/framework/core/src/Api/Resource/DiscussionResource.php +++ b/framework/core/src/Api/Resource/DiscussionResource.php @@ -240,7 +240,7 @@ public function sorts(): array /** @param Discussion $model */ public function creating(object $model, \Tobyz\JsonApiServer\Context $context): ?object { - return Discussion::start(null, $context->getActor()); + return Discussion::start(null, $context->getActor(), $model); } /** @param Discussion $model */ diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 66326bef3f..7835ad4a0f 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -117,13 +117,9 @@ public static function boot() /** * Start a new discussion. Raises the DiscussionWasStarted event. */ - public static function start(?string $title, User $user): static + public static function start(?string $title, User $user, self $model = null): static { - $discussion = new static; - - if ($title) { - $discussion->title = $title; - } + $discussion = $model ?? new static; $discussion->created_at = Carbon::now(); $discussion->user_id = $user->id;