LoginSignup
3
2

More than 5 years have passed since last update.

Laravel Auto Discovery を用いたパッケージ開発

Last updated at Posted at 2018-02-16

モジュール側の composer.json に以下を追加することで auto discovery が働く。

"extra": {
    "laravel": {
        "providers": [
            "ModuleServiceProvider"
        ]
    }
}

auto discovery で検出されたファイルは bootstrap/cache/packages.php に記録される仕組み。

サービスプロバイダであれこれする

ルートを生やす

public function boot()
{
    \Route::prefix("...")->group(function ($route) {
        $route->get(...)
    });
}

設定の追加

    public function register()
    {
        config()->set("mymodule.config", [
        ]);
    }

コンテナ操作

    public function register()
    {
        app()->singleton(....);
        app()->extends(....);
    }

コマンド登録

    public function register()
    {
        $this->commands([
            ....
        ]);
    }

基本的に Laravel の app フォルダは ExceptionHandler 以外触る必要はない

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2