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 th
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.
After you've savely and succesfully setup your .htaccess
(like this), your method will work as you would expect it to work:
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
Be aware that all client-side URL requests (requests to images, JavaScript/CSS files, JSON) will be affected by the Rewrite Rules after you've setup your .htaccess
.
Also be aware that it might take a while after you see the changes. Cache might interfere with these changes. So, make sure you clear your Laravel cache:
In your Shell run the following commands individually:
php artisan cache:clear
php artisan route:cache
php artisan config:cache
php artisan view:clear
And make sure to disable caching temporarily in your browser settings:
In Google Chrome: Open Dev Tools > Open the Network tab > Check "Disable cache".
Other browsers: search online how to do that.
Add in your env:
ASSET_URL=public
or
ASSET_URL=public/
or
ASSET_URL=/public
which one u need u can do it...
<link href="{{ asset('/css/style.css') }}" rel="stylesheet">
Try this