43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\AttendancesResource\Pages;
|
|
|
|
use App\Filament\Resources\AttendancesResource;
|
|
use App\Models\Assessment;
|
|
use App\Models\Attendances;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditAttendances extends EditRecord
|
|
{
|
|
protected static string $resource = AttendancesResource::class;
|
|
|
|
protected function mutateFormDataBeforeSave(array $data): array
|
|
{
|
|
$exists = Attendances::where('teacher_subject_id', $data['teacher_subject_id'])
|
|
->where('student_id', $data['student_id'])
|
|
->where('id', '!=', $this->record->id) // ignore current record
|
|
->exists();
|
|
|
|
if ($exists) {
|
|
Notification::make()
|
|
->title('Failed to save')
|
|
->body('An assessment for this teacher, subject, and student combination already exists.')
|
|
->danger()
|
|
->send();
|
|
|
|
$this->halt();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\DeleteAction::make(),
|
|
];
|
|
}
|
|
}
|