40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\TeacherSubjectResource\Pages;
|
|
|
|
use App\Filament\Resources\TeacherSubjectResource;
|
|
use App\Models\TeacherSubject;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
|
|
class CreateTeacherSubject extends CreateRecord
|
|
{
|
|
protected static string $resource = TeacherSubjectResource::class;
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return 'Tambah Guru per-Mapel';
|
|
}
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
$exists = TeacherSubject::where('teacher_id', $data['teacher_id'])
|
|
->where('subject_id', $data['subject_id'])
|
|
->where('class_id', $data['class_id'])
|
|
->where('academic_year_id', $data['academic_year_id'])
|
|
->exists();
|
|
|
|
if ($exists) {
|
|
Notification::make()
|
|
->title('Failed to save')
|
|
->body('The combination of teacher, subject, class, and academic year is already registered.')
|
|
->danger()
|
|
->send();
|
|
|
|
$this->halt();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|