35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ClassSubjectResource\Pages;
|
|
|
|
use App\Filament\Resources\ClassSubjectResource;
|
|
use App\Models\ClassSubject;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
|
|
class CreateClassSubject extends CreateRecord
|
|
{
|
|
protected static string $resource = ClassSubjectResource::class;
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
$exists = ClassSubject::where('class_room_id', $data['class_room_id'])
|
|
->where('subject_id', $data['subject_id'])
|
|
->where('academic_year_id', $data['academic_year_id'])
|
|
->exists();
|
|
|
|
if ($exists) {
|
|
Notification::make()
|
|
->title('Failed to save')
|
|
->body('A record for this class, subject, and academic year combination already exists.')
|
|
->danger()
|
|
->send();
|
|
|
|
$this->halt(); // Stop the save process
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|