简体   繁体   中英

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:

  1. Publish the package views you want to override:

     php artisan vendor:publish --provider="Another\\Package" --tag=views
  2. Modify the published ones.

  3. Place the modifications in a dir in your package, eg:

     /resources/vendor/another-package/views
  4. Make it available for publishing. Add to your package's service provider boot():

     public function boot() { $this->publishes([ __DIR__.'/resources/vendor/another-package/views' => base_path('resources/views/vendor/another-package') ], 'views'); }
  5. Publish the modifications:

     php artisan vendor:publish --provider="Your\\Package" --tag=views --force

Note: change Another\\Package and another-package as necessary. Works well in Laravel 7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM