注意
メモです。
こんなふうにコード書いていきたい(願望)
慣れたらサイト作って、それをgithubに上げたい(願望)
リポジトリ
class XxxRepository implements XxxRepositoryInterface { }
リポジトリを呼び出すサービス
class XxxService { private $xxx_repository; function __construct(XxxRepositoryInterface $xxx_repository) { $this->xxx_repository = $xxx_repository; } }
XxxRepositoryInterfaceの実装をbind
XxxServiceProvider.php
$this->app->bind( 'App\Repository\XxxRepositoryInterface', 'App\Repository\XxxRepository' );
app.phpにサービスプロバイダを登録するのを忘れずに
忘れそうなよくある質問
Q.バインド?なにこれ?
Q.なんでわざわざインターフェースでやるん?
あとで、インターフェースを使ってテストコードかけるじゃろ。Stub書けるじゃろ。