3

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?

phper
  • 307
  • 2
  • 12

1 Answers1

0

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, e.g.:

     /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.