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.
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:
-
Why can't it find files that are there?
-
Which folders to use: storage/app or storage/app/public or resources/assets?
I'm very confused with it all.
Thank you
Please or to participate in this conversation.