Assets not referencing a shared folder (Laravel)

I have a shared folder inside my laravel project, and I have some js and css files inside.

I use the asset function, and even if I refer to a shared folder, my files are not uploaded to the page.

I use this code to download (this is just one example, there are more files):

<link href="{{ asset('css/style.css') }}" rel="stylesheet"> 

And on the browser console, I get something like this:

Failed to load the resource: the server responded with a status of 404 (not found) http: // localhost: 8000 / css / style.css

Well, I tried to return the last commit, but did not have time. I tried to switch to the function URL :: asset (), 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 help a little?

Thanks!

+8
source share
4 answers

I had the same problem. This involves moving the .htaccess file from the public to the root of the project to serve as localhost/project , not localhost/project/laravel . And it is necessary to use the public as an asset:

 <link href="{{ asset('public/css/app.css') }}" rel="stylesheet"> 

Or change 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 previous method is not a good way. In any case, it would be easier if there was a configuration to set the path to the resources.

+11
source
 <link href="{{ asset('/css/style.css') }}" rel="stylesheet"> 

try it

0
source

try it

 <link href="{{ asset('assets/css/style.css') }}" rel="stylesheet"> 
0
source

After you have successfully and successfully configured your .htaccess ( like this one ), your method will work the way you would like it to work:

 <link href="{{ asset('css/style.css') }}" rel="stylesheet"> 

Keep in mind that all client URL requests (requests for images, JavaScript / CSS files, JSON) will be affected by rewrite rules after setting up your .htaccess .

Also keep in mind that this may take some time after you see the changes. Cache can interfere with these changes. So, make sure you clear the Laravel cache:

In your command console, run the following commands individually:

 php artisan cache:clear php artisan route:cache php artisan config:cache php artisan view:clear 

And be sure to temporarily disable caching in your browser settings:

In Google Chrome: go to "Developer Tools"> open the "Network" tab> check the "Disable cache" box.

Other browsers: search the web for how to do this.

0
source

Source: https://habr.com/ru/post/1259984/


All Articles