fbc's avatar
Level 2

How do you display an image stored in the storage directory??

I recently began using livewire and can't seem to get it to save to the public_path /upload directory so I can formulate an link to display and image.

DetailImageUpload.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithFileUploads;
use App\Models\estimate\Detail;

class DetailImageUpload extends Component
{
    use WithFileUploads;

    public $image;
    public $detail_id;

    public function render()
    {
        return view('livewire.detail-image-upload');
    }

    public function save()
    {
        $this->validate([
            'image' => 'image|max:1024', // 1MB Max
        ]);

        $image = $this->image->storeAs('details', $this->detail_id);
        $data['image'] = $image;
 
        $detail = Detail::find($this->detail_id);
        $detail->update($data);
    }
}

I tried changing the storeAs to '/public/upload' but it ends up only creating that structure under storage.

0 likes
1 reply

Please or to participate in this conversation.