Files
pds/app/Filament/Resources/VisitorEntryResource/Pages/EditVisitorEntry.php
dhanabalan 52af54dbd0
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Added visitor entry resource pages
2026-05-27 11:37:50 +05:30

57 lines
1.7 KiB
PHP

<?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;
}
}