39 lines
1.0 KiB
PHP

<?php
namespace App\Filament\Resources\AttendancesResource\Pages;
use App\Filament\Resources\AttendancesResource;
use App\Models\Assessment;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
class CreateAttendances extends CreateRecord
{
protected static string $resource = AttendancesResource::class;
public function getTitle(): string
{
return 'Tambah Absensi';
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$exists = Assessment::where('teacher_subject_id', $data['teacher_subject_id'])
->where('student_id', $data['student_id'])
->exists();
if ($exists) {
Notification::make()
->title('Failed to save')
->body('A record for this teacher, subject, and student combination already exists.')
->danger()
->send();
$this->halt(); // Stop the save process
}
return $data;
}
}