2025-05-15 10:02:57 +07:00

34 lines
859 B
PHP

<?php
namespace App\Filament\Resources\AcademicYearResource\Pages;
use App\Filament\Resources\AcademicYearResource;
use App\Models\AcademicYear;
use App\Models\ClassStudent;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
class CreateAcademicYear extends CreateRecord
{
protected static string $resource = AcademicYearResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$exists = AcademicYear::where('name', $data['name'])
->exists();
if ($exists) {
Notification::make()
->title('Failed to save')
->body('A record already exists.')
->danger()
->send();
$this->halt(); // Stop the save process
}
return $data;
}
}