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

SigalZ's avatar

asset() and storage:link confusion

Hello, I am very confused with the usage of asset() and storage:link

Should I save my app.js, app.css etc. on the storage folder or in the resources/assets folder?

When I go live (shared hosting), should I move all these css,js, images folders to the public_html folder?

Using laravel 10, I have these folders:

mysite/resources/assets/images

mysite/resources/assets/css

mysite/resources/assets/js

mysite/storage/app/public/images

mysite/storage/app/public/js

mysite/storage/app/public/css

In my config/filesystem:

 'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
            'throw' => false,
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
            'throw' => false,
        ],
...
],

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

In my env file:

ASSET_URL=http://mysite.local/resources/assets/

I ran php artisan storage:link

I ran npm run dev

Running the site on local, it can't find images that are defiantly there.

For example I have an image in folder:

mysite/resources/assets/images/logo-sm.png

When I use dd(asset('images/logo-sm.png')) it gives me the correct path:

http:://mysite/resources/assets/images/logo-sm.png

So, the questions are:

  1. Why can't it find files that are there?

  2. Which folders to use: storage/app or storage/app/public or resources/assets?

I'm very confused with it all.

Thank you

0 likes
8 replies
krisi_gjika's avatar

when you run npm run dev it should build your js and css from your resources into /public folder. You can link to those assets via asset("js/app.js"). As for images I would recommend keeping them in storage/app/public or some sub folder in there so it can be accessed after you run storage:link. An image in resources/assets/images/logo-sm.png is not normally accessible from your browser since that is not a public path. ONLY files in /public can be accessed from your browser.

SigalZ's avatar

@krisi_gjika Thank you.

I moved the images folder from resources/assets to storage/app/public

I ran npm run dev

Now the asset() helper still tries to find the image under resources/assets/images

I changed the ASSET_URL to: ASSET_URL=http://mysite.local/storage/app/public

ran npm run dev again, asset() goes to the right folder yet, I still get 404 not found for the images

krisi_gjika's avatar

@SigalZ again, the goal here is to not access anything outside public/. Check your public folder, there should be a storage folder in there. That folder is symlinked to storage/app/public and we will be using it to access the private storage/app/public folder. So following the structure of the public folder, your images should be in domain + /storage being the name of the folder in public/ + the name of the file, so: mysite.local/storage/image.png. Also you do not need to run npm run dev if you did not update js or css, and if you do you should run watch instead.

1 like
SigalZ's avatar

@krisi_gjika Thank you again, for taking the time to try and help.

Running npm run watch gives me errors:

PS C:\wamp64\www\mysite.local> npm run watch npm ERR! Missing script: "watch" npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run

If I don't run npm run dev I get the error that it can't find the vite manifest resources/assets/js/app.js file

If anyone else has problems, the solution was:

I moved the folders from mysite/public to : mysite/storage/app/public

I ran the storage:link command again

It created the symlinks in mysite/public

And I changed the ASSET_URL in the env file to:

http://mysite.local/storage

Snapey's avatar

The solution is to just store the assets in your public folder. Why does everyone want to make it more complicated and obfuscated by putting stuff in the storage folder?

SigalZ's avatar

@Snapey :o) I don't know, I never used it before, I thought maybe I'm missing something... I guess all I missed was a headache 😂

jlrdw's avatar

@SigalZ just be aware that if a user has private images then those need to be secure, not in public, but somewhere else in the file system.

Myself and others here have given examples of securing user private files and images in past post.

Please or to participate in this conversation.