Laravel5包视图

时间:2014-12-04 12:32:21

标签: php laravel package laravel-5

我已经创建了包“za-web / tags”

composer.json:

{
    "name": "za-web/tags",
    "description": "",
    "authors": [
        {
            "name": "Aleksandr Zamiatin",
            "email": "cawa123@mail.ru"
        }
    ],
    "require": {
        "php": ">=5.4.0",
        "illuminate/support": "5.0.*"
    },
    "autoload": {
        "classmap": [
            "src/views"
        ],
        "psr-4": {
            "ZaWeb\\Tags\\": "src/ZaWeb/Tags"
        }
    },
    "minimum-stability": "dev"
}

要查看我正在尝试的标签

 return View::make('tags::cloud', ['data' => $data])->render();

我收到错误:没有为[tags]定义提示路径。

仅当我在register()方法中添加TagsServiceProvider时才有效:

 View::addNamespace('tags', __DIR__ . '/../../views');

1 个答案:

答案 0 :(得分:1)

您的解决方案有效,但正如Laravel 5 documentation中有关软件包开发的说明,您应该添加到ServiceProvider的引导方法中:

public function boot()
{
    $this->loadViewsFrom(__DIR__.'/path/to/views', 'courier');
}

而不是

 View::addNamespace('tags', __DIR__ . '/../../views');

如果要发布包视图,请不要忘记使用publishes方法:

public function boot()
{
    $this->loadViewsFrom(__DIR__.'/path/to/views', 'courier');

    $this->publishes([
        __DIR__.'/path/to/views' => base_path('resources/views/vendor/courier'),
    ]);
}