34 lines
956 B
PHP
34 lines
956 B
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;
|
|
|
|
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;
|
|
}
|
|
}
|