generated from theradcoza/Laravel-Docker-Dev-Template
Compare commits
1 Commits
shift-mana
...
shift-mana
| Author | SHA1 | Date | |
|---|---|---|---|
| 2475daca4b |
@@ -56,7 +56,7 @@ public static function form(Form $form): Form
|
||||
Forms\Components\Select::make('staffMembers')
|
||||
->label('Assign Staff')
|
||||
->multiple()
|
||||
->relationship('staff', 'name')
|
||||
->options(User::query()->pluck('name', 'id'))
|
||||
->preload()
|
||||
->searchable(),
|
||||
])
|
||||
|
||||
@@ -17,4 +17,17 @@ protected function mutateFormDataBeforeCreate(array $data): array
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$staffIds = $this->data['staffMembers'] ?? [];
|
||||
|
||||
if (empty($staffIds)) {
|
||||
return;
|
||||
}
|
||||
$this->record->staff()->syncWithPivotValues(
|
||||
$staffIds,
|
||||
['assigned_by' => auth()->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,4 +54,14 @@ protected function getHeaderActions(): array
|
||||
->visible(fn () => $this->record->isPlanned()),
|
||||
];
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$staffIds = $this->data['staffMembers'] ?? [];
|
||||
|
||||
$this->record->staff()->syncWithPivotValues(
|
||||
$staffIds,
|
||||
['assigned_by' => auth()->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,13 @@ public function table(Table $table): Table
|
||||
Tables\Actions\AttachAction::make()
|
||||
->label('Add Staff')
|
||||
->preloadRecordSelect()
|
||||
->visible(fn () => $this->getOwnerRecord()->isPlanned()),
|
||||
->visible(fn () => $this->getOwnerRecord()->isPlanned())
|
||||
->action(function (array $data, $ownerRecord) {
|
||||
$staffId = $data['record'] ?? null;
|
||||
if ($staffId) {
|
||||
app(\App\Services\ShiftService::class)->assignStaff($ownerRecord, [$staffId]);
|
||||
}
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\DetachAction::make()
|
||||
|
||||
@@ -29,6 +29,7 @@ public function createShift(array $data, ?array $staffIds = null): Shift
|
||||
]);
|
||||
|
||||
if ($staffIds) {
|
||||
logger()->info('Staff IDs:', $staffIds);
|
||||
$this->assignStaff($shift, $staffIds);
|
||||
}
|
||||
|
||||
@@ -102,6 +103,11 @@ public function assignStaff(Shift $shift, array $staffIds): void
|
||||
}
|
||||
|
||||
$managerId = Auth::id();
|
||||
|
||||
if(!$managerId) {
|
||||
throw new InvalidArgumentException('Authenticated user is required to assign staff.');
|
||||
}
|
||||
|
||||
$syncData = [];
|
||||
|
||||
foreach ($staffIds as $staffId) {
|
||||
|
||||
@@ -13,11 +13,24 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Create the admin user
|
||||
User::factory()->create([
|
||||
'name' => 'Admin User',
|
||||
'email' => 'admin@example.com',
|
||||
]);
|
||||
|
||||
// Create 10 random staff users
|
||||
User::factory()->create(['name' => 'Staff One', 'email' => 'staff1@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Two', 'email' => 'staff2@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Three', 'email' => 'staff3@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Four', 'email' => 'staff4@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Five', 'email' => 'staff5@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Six', 'email' => 'staff6@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Seven', 'email' => 'staff7@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Eight', 'email' => 'staff8@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Nine', 'email' => 'staff9@example.com']);
|
||||
User::factory()->create(['name' => 'Staff Ten', 'email' => 'staff10@example.com']);
|
||||
|
||||
$this->call(RolePermissionSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user