12

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)

1 Answer 1

22

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'));
Sign up to request clarification or add additional context in comments.

3 Comments

Nova::style('admin', asset('css/admin.css')); use asset instead of public_path ( V3 )
To add to that, one can use it together with Vite: Nova::style('custom-nova', Vite::asset('resources/scss/nova/nova.scss'));
This work but after login before that the file not include

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.