在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):打开失败 流:无法分配请求的地址 {“例外”:“ [对象] (ErrorException(代码:0): file_get_contents(http://localhost:8099/css/admin.css):打开失败 流:无法在分配请求的地址 /var/www/nova/src/Http/Controllers/StyleController.php:20)
答案 0 :(得分:4)
Nova::style
用于将样式添加到现有包中。因此,Laravel Nova需要CSS文件的直接路径,以便可以对其进行解析。使用函数public_path
获取公用文件夹中文件的绝对路径。这样,Nova可以读取文件。
Nova::style('admin', public_path('css/admin.css'));