Refactor ShiftForm to streamline field definitions and implement unique code generation for shifts based on their names. Update ShiftFactory to utilize the new code generation method.

This commit is contained in:
Mekan1206
2026-08-02 20:17:16 +05:00
parent e3ec83686c
commit 28cbef8eb5
4 changed files with 99 additions and 23 deletions

View File

@@ -27,14 +27,16 @@ class ShiftFactory extends Factory
default => ['starts_at' => '22:00:00', 'ends_at' => '06:00:00'],
};
$name = match ($code) {
'A' => 'Morning Shift',
'B' => 'Afternoon Shift',
'C' => 'Evening Shift',
default => 'Night Shift',
};
return [
'name' => match ($code) {
'A' => 'Morning Shift',
'B' => 'Afternoon Shift',
'C' => 'Evening Shift',
default => 'Night Shift',
},
'code' => $code.'-'.fake()->unique()->numerify('###'),
'name' => $name,
'code' => Shift::generateUniqueCodeFromName($name),
'starts_at' => $times['starts_at'],
'ends_at' => $times['ends_at'],
'description' => fake()->optional()->sentence(),