changed logic in create visitor
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
This commit is contained in:
@@ -14,12 +14,14 @@ class CreateVisitorEntry extends CreateRecord
|
|||||||
{
|
{
|
||||||
protected static string $resource = VisitorEntryResource::class;
|
protected static string $resource = VisitorEntryResource::class;
|
||||||
|
|
||||||
#[On('photo-captured')]
|
public $capturedPhoto;
|
||||||
public function handlePhotoCapture(string $photo): void
|
|
||||||
{
|
// #[On('photo-captured')]
|
||||||
// Puts the Base64 photo into the form's data array
|
// public function handlePhotoCapture(string $photo): void
|
||||||
$this->data['photo'] = $photo;
|
// {
|
||||||
}
|
// // Puts the Base64 photo into the form's data array
|
||||||
|
// $this->data['photo'] = $photo;
|
||||||
|
// }
|
||||||
|
|
||||||
public function processMobile($mobile)
|
public function processMobile($mobile)
|
||||||
{
|
{
|
||||||
@@ -53,26 +55,62 @@ class CreateVisitorEntry extends CreateRecord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function mutateFormDataBeforeCreate(array $data): array
|
// protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
{
|
// {
|
||||||
if (
|
// if (
|
||||||
!empty($data['photo']) &&
|
// !empty($data['photo']) &&
|
||||||
str_starts_with($data['photo'], 'data:image')
|
// str_starts_with($data['photo'], 'data:image')
|
||||||
) {
|
// ) {
|
||||||
// Step A: Strip the "data:image/jpeg;base64," prefix
|
// // Step A: Strip the "data:image/jpeg;base64," prefix
|
||||||
$imageData = explode(',', $data['photo'])[1];
|
// $imageData = explode(',', $data['photo'])[1];
|
||||||
|
|
||||||
// Step B: Generate a unique filename
|
// // Step B: Generate a unique filename
|
||||||
$filename = 'visitor_' . time() . '_' . uniqid() . '.jpg';
|
// $filename = 'visitor_' . time() . '_' . uniqid() . '.jpg';
|
||||||
|
|
||||||
// Step C: Decode Base64 and save as a real .jpg file
|
// // Step C: Decode Base64 and save as a real .jpg file
|
||||||
$path = 'visitor-photos/' . $filename;
|
// $path = 'visitor-photos/' . $filename;
|
||||||
Storage::disk('public')->put($path, base64_decode($imageData));
|
// Storage::disk('public')->put($path, base64_decode($imageData));
|
||||||
|
|
||||||
// Step D: Replace the Base64 string with just the file path
|
// // Step D: Replace the Base64 string with just the file path
|
||||||
$data['photo'] = $path;
|
// $data['photo'] = $path;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $data;
|
||||||
|
// }
|
||||||
|
|
||||||
|
#[On('photo-captured')]
|
||||||
|
public function handlePhotoCapture(string $photo): void
|
||||||
|
{
|
||||||
|
$this->data['photo'] = $photo;
|
||||||
|
\Log::info('WEBCAM: photo-captured event received, length: ' . strlen($photo));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
}
|
{
|
||||||
|
\Log::info('WEBCAM: mutateFormDataBeforeCreate called, photo value: ' . substr($data['photo'] ?? 'NULL', 0, 50));
|
||||||
|
|
||||||
|
if (
|
||||||
|
!empty($data['photo']) &&
|
||||||
|
str_starts_with($data['photo'], 'data:image')
|
||||||
|
) {
|
||||||
|
$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;
|
||||||
|
|
||||||
|
\Log::info('WEBCAM: photo saved to ' . $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function setPhoto(string $photo): void
|
||||||
|
{
|
||||||
|
$this->capturedPhoto = $photo;
|
||||||
|
|
||||||
|
// Change this ↓ to dispatch to parent explicitly
|
||||||
|
$this->dispatch('photo-captured', photo: $photo)->to(\App\Filament\Resources\VisitorEntryResource\Pages\CreateVisitorEntry::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user