Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

secondman's avatar

Storage Link Not Working

I used the the artisan command storage:link to link to the storage/app/public directory but when I call {{ asset('storage/img/myimage.jpg') }} in my blade files I get a 404 not found.

What exactly am I doing wrong?

0 likes
13 replies
AddWebContribution's avatar

You can try:

Create the special route for that

Route::get('images/{filename}', function ($filename)
{
    $path = storage_path() . '/img/' . $filename;

    if(!File::exists($path)) abort(404);

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;
});

And access a file from this route url /images/{filename}.

2 likes
bobbybouwmann's avatar

The asset helper starts at the root of your project. However the files in the storage directory are not accessible publicly by default. You need to create your own file response for that like @saurabh said.

secondman's avatar

None of this should be necessary.

The symlink should work automatically.

secondman's avatar

@bobbybouwmann

According to the documentation I should be able to use the storage:link command to create a symlink from public/storage to storage/app/public

Then use the asset('storage/img/myimage.jpg') helper to display the image in a template.

My question is, what are some reasons it might not be working correctly? Permission problems? Or something else?

I'm working on a Mac with Homestead.

secondman's avatar
secondman
OP
Best Answer
Level 17

Ok I figured it out.

I made the symlink originally in my local console, and it turns out you need to make it under homestead.

All is working correctly now.

Thanks @saurabhd and @bobbybouwmann

7 likes
wobstuff's avatar

I had a similar issue using Laradock. I had to exec into the Workspace container and run the command from there after deleting the symbolic link I had made from my local terminal.

bobbybouwmann's avatar

Yeah indeed, you need to create the symlink in your homestead box.

2 likes
COACHTHEM's avatar

Ok I figured this out. here are the steps to follow

SYMBOLIC LINK ON MAC - HOMESTEAD EVN
- ssh into your homestead using below command 
- cd ~homestead
- vagrant up
- vagrant ssh
- cd Code/PATH_TO_YOUR_APP_ROOT_DIR
- php artisan storage:link

when executing you might get error saying

In Filesystem.php line 228:
symlink(): No such file or directory

cd into your local app directory and unlink the already created symbolic link with this command

// Assuming you are at the root of your project
rm -rf public/storage

ssh again into your virtual box to your app folder and run php artisan storage:link again. With this you should be good

Thanks

4 likes
saber13812002's avatar

visit laravel documentation

'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('images') => storage_path('app/images'),
],

krzysztofpietrzak's avatar

Hello, I have the same problem, but I don't even know where to enter commands and commands I don't know what the line or terminal is, please help I use laraclasified and I also accidentally deleted storage directory restoration backup from hard disk to server I won't help symbolic command to do

Please or to participate in this conversation.