Skip to content

Commit f54eb5a

Browse files
committed
Improve guid fill when creating incident
1 parent 636c056 commit f54eb5a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/Filament/Resources/IncidentResource.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ public static function form(Form $form): Form
7575
Forms\Components\Toggle::make('notifications')
7676
->label(__('Send notifications to subscribers.'))
7777
->required(),
78-
Forms\Components\TextInput::make('guid')
79-
->required()
80-
->default(fn () => (string) Str::uuid())
81-
->unique(ignoreRecord: true)
82-
->maxLength(36)
83-
->hidden(),
8478
]),
8579
]);
8680
}

src/Models/Incident.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ class Incident extends Model
4848
'occurred_at',
4949
];
5050

51+
protected static function boot()
52+
{
53+
parent::boot();
54+
55+
self::creating(function (Incident $model) {
56+
$model->guid = Str::uuid();
57+
});
58+
}
59+
5160
/**
5261
* Get the components impacted by this incident.
5362
*/

tests/Unit/Models/IncidentTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
expect($incident->components)->toHaveCount(2);
1010
});
1111

12+
it('will set default guid', function () {
13+
$incident = Incident::factory()->state(['guid' => null])->create();
14+
15+
expect($incident)->guid->not()->toBeNull();
16+
});
17+
1218
it('can scope to a specific status', function () {
1319
Incident::factory()->sequence(
1420
['status' => IncidentStatusEnum::investigating],

0 commit comments

Comments
 (0)