[英]Is it possible to override a laravel package view from another package
Is it possible to override package view from another package?是否可以从另一个包覆盖包视图?
When you register a view path via当您通过以下方式注册视图路径时
loadViewsFrom('path/to/views', 'package')
it will also look in它也会查看
/resources/views/vendor/package
So you can override a view when using a package,所以你可以在使用包时覆盖视图,
but is there a way to override a view within a different package?但是有没有办法覆盖不同包中的视图?
Yes it is.是的。
Steps:脚步:
Publish the package views you want to override:发布要覆盖的包视图:
php artisan vendor:publish --provider="Another\\Package" --tag=views
Modify the published ones.修改已发布的。
Place the modifications in a dir in your package, eg:将修改放在包中的目录中,例如:
/resources/vendor/another-package/views
Make it available for publishing.使其可用于发布。 Add to your package's service provider boot():
添加到您的包的服务提供者 boot():
public function boot() { $this->publishes([ __DIR__.'/resources/vendor/another-package/views' => base_path('resources/views/vendor/another-package') ], 'views'); }
Publish the modifications:发布修改:
php artisan vendor:publish --provider="Your\\Package" --tag=views --force
Note: change Another\\Package
and another-package
as necessary.注意:根据需要更改
Another\\Package
和another-package
。 Works well in Laravel 7.在 Laravel 7 中运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.