11

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)

Saumini Navaratnam
  • 8,439
  • 3
  • 42
  • 70

1 Answers1

20

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'));
Jerodev
  • 32,252
  • 11
  • 87
  • 108