From ae390a9f505d96061f67d2b50024e775ce19e2c1 Mon Sep 17 00:00:00 2001 From: Emmanuel Lampe Date: Fri, 4 Dec 2020 14:50:16 +0100 Subject: [PATCH] Moved uuid generation from model to observer --- src/Observers/TicketObserver.php | 8 ++++++++ src/Traits/HasConfigModel.php | 12 ------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Observers/TicketObserver.php b/src/Observers/TicketObserver.php index 8a99801..70cefbb 100644 --- a/src/Observers/TicketObserver.php +++ b/src/Observers/TicketObserver.php @@ -4,6 +4,7 @@ namespace RexlManu\LaravelTickets\Observers; +use Ramsey\Uuid\Uuid; use RexlManu\LaravelTickets\Events\TicketCloseEvent; use RexlManu\LaravelTickets\Events\TicketOpenEvent; use RexlManu\LaravelTickets\Models\Ticket; @@ -44,4 +45,11 @@ public function deleting(Ticket $ticket) $ticket->messages()->get()->each(fn(TicketMessage $ticketMessage) => $ticketMessage->delete()); } + public function creating(Ticket $ticket) + { + if (config('laravel-tickets.model.uuid') && empty($model->id)) { + $ticket->id = Uuid::uuid4(); + } + } + } diff --git a/src/Traits/HasConfigModel.php b/src/Traits/HasConfigModel.php index 92c864d..78633c0 100644 --- a/src/Traits/HasConfigModel.php +++ b/src/Traits/HasConfigModel.php @@ -4,8 +4,6 @@ namespace RexlManu\LaravelTickets\Traits; -use Ramsey\Uuid\Uuid; - trait HasConfigModel { @@ -18,14 +16,4 @@ public function isIncrementing() { return config('laravel-tickets.model.incrementing'); } - - public static function bootHasUuid() - { - static::creating(function ($model) { - if (config('laravel-tickets.model.uuid') && empty($model->id)) { - $model->id = Uuid::uuid4(); - } - }); - } - }