I have the public folder inside my laravel project and I have some js and css files inside it.
I'm using the asset function and even though it's referencing to the public folder, my files aren't loaded on the page.
I'm using this code to load (it's only one example, there are more files):
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
And on the browser's console, I'm geting something like this:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8000/css/style.css
Well, I tried to revert the last commit, but no success. Tried to change to URL::asset() function, nothing. Tried everything from the following link: http://laravel.io/forum/09-17-2014-problem-asset-not-point-to-public-folder?page=1 and success.
Please, a little help?
Thanks!
Put them inside public/images . The resources/assets/ directory is for storing 'pre-processed' assets, so to speak. For example, if you have 3 different CSS files but want to merge them into one and render that new single file in the browser (to increase page load speed).
The storage/app/public directory may be used to store user-generated files, such as profile avatars, that should be publicly accessible. You should create a symbolic link at public/storage which points to this directory. You may create the link using the php artisan storage:link Artisan command.
This is a typical Laravel folder structure, with the default public folder : / /app /bootstrap /config /database /public /index.php /resources /routes /storage. This is specially useful when you try to deploy or publish your application in a standard web server.
I was having same problem. This is due to moving of .htaccess file from public to root of the project in order to serve localhost/project
rather than localhost/project/laravel
. And needed to use public as well in the asset:
<link href="{{ asset('public/css/app.css') }}" rel="stylesheet">
Or, modify the asset function from /Illuminate/Foundation/helpers.php
if (! function_exists('asset')) {
/**
* Generate an asset path for the application.
*
* @param string $path
* @param bool $secure
* @return string
*/
function asset($path, $secure = null)
{
return app('url')->asset("public/".$path, $secure);
}
}
The preceding method is not good way. Anyway this would have been easier if there was config for setting asset path.
Add in your env
:
ASSET_URL=public
or
ASSET_URL=public/
or
ASSET_URL=/public
which one u need u can do it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With