Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...