Added visitor entry resource pages
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-05-27 11:37:50 +05:30
parent 173a9e40a9
commit 52af54dbd0
5 changed files with 573 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Filament\Resources\VisitorEntryResource\Pages;
use App\Filament\Resources\VisitorEntryResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\On;
class EditVisitorEntry extends EditRecord
{
protected static string $resource = VisitorEntryResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
// Receives the photo from the webcam component
#[On('photo-captured')]
public function handlePhotoCapture(string $photo): void
{
$this->data['photo'] = $photo;
}
// Runs automatically before the record is updated in the database
protected function mutateFormDataBeforeSave(array $data): array
{
if (
!empty($data['photo']) &&
str_starts_with($data['photo'], 'data:image')
) {
// Delete the old photo file if one exists
$oldPhoto = $this->record->photo;
if ($oldPhoto && Storage::disk('public')->exists($oldPhoto)) {
Storage::disk('public')->delete($oldPhoto);
}
// Save the new photo
$imageData = explode(',', $data['photo'])[1];
$filename = 'visitor_' . time() . '_' . uniqid() . '.jpg';
$path = 'visitor-photos/' . $filename;
Storage::disk('public')->put($path, base64_decode($imageData));
$data['photo'] = $path;
}
return $data;
}
}