Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Nova - Include additional css files

In Laravel Nova, how to include additional css files?

I have tried following, but gives an error.

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
    * Bootstrap any application services.
    *
    * @return void
    */
    public function boot()
    {
        parent::boot();

        Nova::style('admin', asset('css/admin.css'));
    }
    ...
}

Under public/css folder I have admin.css file.

Error:

file_get_contents(http://localhost:8099/css/admin.css): failed to open stream: Cannot assign requested address {"exception":"[object] (ErrorException(code: 0): file_get_contents(http://localhost:8099/css/admin.css): failed to open stream: Cannot assign requested address at /var/www/nova/src/Http/Controllers/StyleController.php:20)

like image 600
Saumini Navaratnam Avatar asked Oct 02 '18 11:10

Saumini Navaratnam


1 Answers

Nova::style is used to add styles to the existing bundles. Therefor, Laravel Nova needs a direct path to the CSS file so these can be parsed. Use the function public_path to get an absolute path to files in the public folder. This way, Nova can read the files.

Nova::style('admin', public_path('css/admin.css'));
like image 200
Jerodev Avatar answered Sep 19 '22 21:09

Jerodev