是否可以从另一个包中覆盖包视图?通过以下方式注册视图路径时loadViewsFrom('path/to/views', 'package')
它也会在/resources/views/vendor/package
因此,您可以在使用包时覆盖视图,但是有办法覆盖其他包中的视图吗?
是。
步骤:
发布要覆盖的包视图:
php artisan vendor:publish --provider="Another\Package" --tag=views
修改已发布的内容。
将修改内容放入您程序包的目录中,例如:
/resources/vendor/another-package/views
使其可发布。添加到包的服务提供者boot():
public function boot()
{
$this->publishes([
__DIR__.'/resources/vendor/another-package/views' =>
base_path('resources/views/vendor/another-package')
], 'views');
}
发布修改:
php artisan vendor:publish --provider="Your\Package" --tag=views --force
注意:根据需要更改Another\Package
和another-package
。在Laravel 7中效果很好。