41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\HomeRoomTeacherResource\Pages;
|
|
|
|
use App\Filament\Resources\HomeRoomTeacherResource;
|
|
use App\Models\ClassStudent;
|
|
use App\Models\HomeRoomTeacher;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
|
|
class CreateHomeRoomTeacher extends CreateRecord
|
|
{
|
|
protected static string $resource = HomeRoomTeacherResource::class;
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return 'Tambah Guru Wali Kelas';
|
|
}
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
$exists = HomeRoomTeacher::where('class_room_id', $data['class_room_id'])
|
|
->where('teacher_id', $data['teacher_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, teacher, and academic year combination already exists.')
|
|
->danger()
|
|
->send();
|
|
|
|
$this->halt(); // Stop the save process
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|