Laravel Nova - 包括额外的 css 文件
Laravel Nova - Include additional css files
在 Laravel Nova 中,如何包含额外的 css 文件?
我试过跟随,但是报错。
class NovaServiceProvider extends NovaApplicationServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
Nova::style('admin', asset('css/admin.css'));
}
...
}
在 public/css
文件夹下我有 admin.css
个文件。
错误:
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)
Nova::style
用于向现有包中添加样式。因此,Laravel Nova 需要 CSS 文件的直接路径,以便可以解析这些文件。使用函数 public_path
获取 public 文件夹中文件的绝对路径。这样,Nova 就可以读取文件了。
Nova::style('admin', public_path('css/admin.css'));
在 Laravel Nova 中,如何包含额外的 css 文件?
我试过跟随,但是报错。
class NovaServiceProvider extends NovaApplicationServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
Nova::style('admin', asset('css/admin.css'));
}
...
}
在 public/css
文件夹下我有 admin.css
个文件。
错误:
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)
Nova::style
用于向现有包中添加样式。因此,Laravel Nova 需要 CSS 文件的直接路径,以便可以解析这些文件。使用函数 public_path
获取 public 文件夹中文件的绝对路径。这样,Nova 就可以读取文件了。
Nova::style('admin', public_path('css/admin.css'));