Skip to content

Commit ae390a9

Browse files
committed
Moved uuid generation from model to observer
1 parent 3a0a7f8 commit ae390a9

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/Observers/TicketObserver.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace RexlManu\LaravelTickets\Observers;
55

66

7+
use Ramsey\Uuid\Uuid;
78
use RexlManu\LaravelTickets\Events\TicketCloseEvent;
89
use RexlManu\LaravelTickets\Events\TicketOpenEvent;
910
use RexlManu\LaravelTickets\Models\Ticket;
@@ -44,4 +45,11 @@ public function deleting(Ticket $ticket)
4445
$ticket->messages()->get()->each(fn(TicketMessage $ticketMessage) => $ticketMessage->delete());
4546
}
4647

48+
public function creating(Ticket $ticket)
49+
{
50+
if (config('laravel-tickets.model.uuid') && empty($model->id)) {
51+
$ticket->id = Uuid::uuid4();
52+
}
53+
}
54+
4755
}

src/Traits/HasConfigModel.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace RexlManu\LaravelTickets\Traits;
55

66

7-
use Ramsey\Uuid\Uuid;
8-
97
trait HasConfigModel
108
{
119

@@ -18,14 +16,4 @@ public function isIncrementing()
1816
{
1917
return config('laravel-tickets.model.incrementing');
2018
}
21-
22-
public static function bootHasUuid()
23-
{
24-
static::creating(function ($model) {
25-
if (config('laravel-tickets.model.uuid') && empty($model->id)) {
26-
$model->id = Uuid::uuid4();
27-
}
28-
});
29-
}
30-
3119
}

0 commit comments

Comments
 (0)