Skip to content

Commit

Permalink
Moved uuid generation from model to observer
Browse files Browse the repository at this point in the history
  • Loading branch information
rexlManu committed Dec 4, 2020
1 parent 3a0a7f8 commit ae390a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/Observers/TicketObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

}
12 changes: 0 additions & 12 deletions src/Traits/HasConfigModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace RexlManu\LaravelTickets\Traits;


use Ramsey\Uuid\Uuid;

trait HasConfigModel
{

Expand All @@ -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();
}
});
}

}

0 comments on commit ae390a9

Please sign in to comment.