Assets not referencing to public folder (Laravel)

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="https://stackoverflow.com/questions/40682748/{{ 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.

Leave a Comment