From 46c6dd6e58101426f8258cca8f56a3b809fe9813 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Sun, 13 Apr 2025 22:17:37 +0100 Subject: [PATCH] feat: add id setter for the Task model --- src/Models/Task.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Models/Task.php b/src/Models/Task.php index 3c130cb..ee0ebee 100644 --- a/src/Models/Task.php +++ b/src/Models/Task.php @@ -88,7 +88,13 @@ class Task } - public static function fromArray($taskData): Task + public function setId(int $id): Task + { + $this->id = $id; + return $this; + } + + public static function fromArray($taskData): self { $task = new self(); @@ -109,7 +115,8 @@ class Task public function persist(): array { return [ - 'task_owner' => 1, // fake hard-coded user for now + 'id' => $this->id ?? null, + 'task_owner' => 1, // fake hard-coded user for now 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), 'name' => $this->getTitle(), @@ -117,7 +124,6 @@ class Task 'start' => $this->getStartDt(), 'end' => $this->getEndDt(), 'status_id' => $this->getStatus()->value - ]; }