diff --git a/app/Filament/Resources/VisitorEntryResource/Pages/CreateVisitorEntry.php b/app/Filament/Resources/VisitorEntryResource/Pages/CreateVisitorEntry.php index e274daf..e25f60e 100644 --- a/app/Filament/Resources/VisitorEntryResource/Pages/CreateVisitorEntry.php +++ b/app/Filament/Resources/VisitorEntryResource/Pages/CreateVisitorEntry.php @@ -10,6 +10,8 @@ use Filament\Actions\Action; use Filament\Resources\Pages\CreateRecord; use Illuminate\Support\Facades\Storage; use Livewire\Attributes\On; +use App\Mail\VisitorMail; +use Illuminate\Support\Facades\Mail; class CreateVisitorEntry extends CreateRecord { @@ -118,6 +120,21 @@ class CreateVisitorEntry extends CreateRecord ]; } + protected function afterCreate(): void + { + $visitor = $this->record; + + $employee = EmployeeMaster::find($visitor->employee_master_id); + + if ($employee && !empty($employee->email)) { + Mail::to($employee->email) + ->send(new VisitorMail($visitor)); // or ->send() + } + else{ + \Log::warning('No email found for employee ID: ' . $visitor->employee_master_id); + } + } + protected function getRedirectUrl(): string { return $this->getResource()::getUrl('view', ['record' => $this->record]);