はじめに サービスコンテナは、 Laravelのコアとなる機能で Laravelのめちゃくちゃ便利で魔法のような仕組みを 実現してくれているものです。 しかし、普段Laravelを使っていても 簡単なアプリケーションを作るうえではあまり意識しないところかもしれません。 (意識しなくていいようになってる) このサービスコンテナについて理解すると、 より便利に自分でカスタマイズしたりできるし、 何より面白いです。 Laravelのサービスコンテナとは何なのかについて 調べましたので、簡単に解説します。 サービスコンテナとは サービスコンテナとは、 一言でいうと 「クラスをインスタンス化してくれるマシーン」 というイメージ。 具体的なコードで見てみます。 ClassAをインスタンス化するとき、 普通はこのようにnewしますね。