是否有可能从另一个软件包替代laravel软件包视图

问题描述 投票:0回答:1

是否可以从另一个包中覆盖包视图?通过以下方式注册视图路径时loadViewsFrom('path/to/views', 'package')它也会在/resources/views/vendor/package因此,您可以在使用包时覆盖视图,但是有办法覆盖其他包中的视图吗?

php laravel laravel-blade laravel-5.8 php-7.3
1个回答
0
投票

是。

步骤:

  1. 发布要覆盖的包视图:

    php artisan vendor:publish --provider="Another\Package" --tag=views
    
  2. 修改已发布的内容。

  3. 将修改内容放入您程序包的目录中,例如:

     /resources/vendor/another-package/views
    
  4. 使其可发布。添加到包的服务提供者boot():

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

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

注意:根据需要更改Another\Packageanother-package。在Laravel 7中效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.