36 lines
1.0 KiB
PHP
36 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ClassStudentResource\Pages;
|
|
|
|
use App\Filament\Resources\ClassStudentResource;
|
|
use App\Models\Assessment;
|
|
use App\Models\ClassStudent;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
|
|
class CreateClassStudent extends CreateRecord
|
|
{
|
|
protected static string $resource = ClassStudentResource::class;
|
|
|
|
protected function mutateFormDataBeforeCreate(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;
|
|
}
|
|
}
|