diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php new file mode 100644 index 0000000..f3d299c --- /dev/null +++ b/app/Http/Controllers/PhotoController.php @@ -0,0 +1,11 @@ +status = 'Error: Invalid image data'; + return; + } + + $extension = strtolower($type[1]); + $filename = 'photos/' . Str::uuid() . '.' . $extension; + $raw = base64_decode(substr($imageData, strpos($imageData, ',') + 1)); + + Storage::disk('public')->put($filename, $raw); + + $job = PhotoJob::create([ + 'image_path' => $filename, + 'status' => 'pending', + ]); + + $this->status = "Job #{$job->id} created"; + } + + public function render() + { + $recentPhotos = PhotoJob::latest()->take(10)->get()->map(fn($job) => [ + 'id' => $job->id, + 'url' => Storage::disk('public')->url($job->image_path), + 'status' => $job->status, + ]); + + return view('livewire.camera-capture', compact('recentPhotos')); + } +} diff --git a/resources/views/camera.blade.php b/resources/views/camera.blade.php new file mode 100644 index 0000000..bf05846 --- /dev/null +++ b/resources/views/camera.blade.php @@ -0,0 +1,20 @@ + + + + + + Fotobox + @if (file_exists(public_path('build/manifest.json')) || file_exists(public_path('hot'))) + @vite(['resources/css/app.css', 'resources/js/app.js']) + @endif + @livewireStyles + + + +

Fotobox

+ + @livewire('camera-capture') + + @livewireScripts + + diff --git a/resources/views/livewire/camera-capture.blade.php b/resources/views/livewire/camera-capture.blade.php new file mode 100644 index 0000000..74560e0 --- /dev/null +++ b/resources/views/livewire/camera-capture.blade.php @@ -0,0 +1,75 @@ +
+
+ + + + +
+
+ + + +
{{ $status }}
+ + @if ($recentPhotos->isNotEmpty()) +
+

Recent Photos

+
+ @foreach ($recentPhotos as $photo) +
+ Photo #{{ $photo['id'] }} + + {{ $photo['status'] }} + +
+ @endforeach +
+
+ @endif + + @script + + @endscript +
diff --git a/routes/web.php b/routes/web.php index 86a06c5..e37a6e7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,6 @@ name('camera');