42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ClassStudentResource\Pages;
|
|
|
|
use App\Filament\Resources\ClassStudentResource;
|
|
use App\Models\ClassStudent;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditClassStudent extends EditRecord
|
|
{
|
|
protected static string $resource = ClassStudentResource::class;
|
|
|
|
protected function mutateFormDataBeforeSave(array $data): array
|
|
{
|
|
$exists = ClassStudent::where('class_room_id', $data['class_room_id'])
|
|
->where('student_id', $data['student_id'])
|
|
->where('academic_year_id', $data['academic_year_id'])
|
|
->exists();
|
|
|
|
if ($exists) {
|
|
Notification::make()
|
|
->title('Failed to save')
|
|
->body('A record for this class room, student, and academic year combination already exists.')
|
|
->danger()
|
|
->send();
|
|
|
|
$this->halt(); // Stop the save process
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\DeleteAction::make(),
|
|
];
|
|
}
|
|
}
|