ride = $ride; } public function toggleUploadForm(): void { $this->showUploadForm = !$this->showUploadForm; $this->reset(['photo', 'caption']); } public function save(): void { $this->validate([ 'photo' => 'required|image|max:10240', 'caption' => 'nullable|string|max:255', ]); $path = $this->photo->store('ride-photos', 'public'); $this->ride->photos()->create([ 'path' => $path, 'caption' => $this->caption, 'uploaded_by' => Auth::id(), ]); $this->reset(['photo', 'caption']); $this->showUploadForm = false; session()->flash('message', 'Photo uploaded successfully.'); } public function deletePhoto(int $photoId): void { $photo = $this->ride->photos()->findOrFail($photoId); if ($photo->uploaded_by === Auth::id() || Gate::allows('delete-any-photo')) { Storage::disk('public')->delete($photo->path); $photo->delete(); session()->flash('message', 'Photo deleted successfully.'); } else { session()->flash('error', 'You do not have permission to delete this photo.'); } } public function setFeaturedPhoto(int $photoId): void { if (Gate::allows('edit', $this->ride)) { $this->ride->featured_photo_id = $photoId; $this->ride->save(); session()->flash('message', 'Featured photo updated.'); } else { session()->flash('error', 'You do not have permission to set the featured photo.'); } } public function render() { return view('livewire.ride-gallery', [ 'photos' => $this->ride->photos()->latest()->paginate(12), ]); } }