skoobi's avatar
Level 13

Cannot display image from local storage

Hi. I can't for the life of me retrieve and display an image from local storage. It all worked using

I've set up the simlink and its set to local in the config/filesystem.

The files are saving to the correct place and when i right click the image, it is pointing to the correct place but it still shows 404 error.

I've tried a handful of different locations including '/storage/app', '/storage/' and so on but still nothing.

Upload Code in Controller

$file = $request->file('job_image');
            $path = $file->hashName('/users/' . \Auth::id() . '/jobs/' . \Carbon\Carbon::now()->toDateString());

            $image = Image::make($file);

            $image->fit(1200, 800, function ($constraint) {
                $constraint->aspectRatio();
            });

            Storage::put($path, (string) $image->encode());

This saves the path as /users/2/jobs/2018-01-11/5r77oB7xhXSSsg81pIGJo5yN9g8yiqKHxtkYT20f.jpeg in the db...

VIew:

<img class="job-card" src="{!! Storage::disk('local')->url($job->img_path) !!}" alt="{{ $job->category['name'] }}">

Any ideas on what i'm doing wrong?

0 likes
5 replies
biishmar's avatar

You cannot access image or file directly from storage/app as a url, if u want to access the image from storage folder use public disk or save the image in public folder.

skoobi's avatar
Level 13

Ah ok so basically I need to store it into something like /public/images/users etc.

How would I store the images in the public folder?

Many thanks.

skoobi's avatar
Level 13

Brilliant many thanks. I'm sure I did this but will give it another go...

biishmar's avatar

use native php function

file_put_content($path, $filename)

OR use composer package Intervention/Image for more laravel like coding.

Please or to participate in this conversation.