我在 Laravel 存儲(chǔ)庫中很新。我正在使用l5-repository 包。當(dāng)我創(chuàng)建資源控制器時(shí),它創(chuàng)建如下:?public?function?__construct(MyRepository?$repository,?MyValidator?$validator)????{?
????????$this->repository?=?$repository;?
???????????????$this->validator??=?$validator;
????}我可以在這個(gè)控制器中獲得MyRepository實(shí)例。$this->repository但是我需要在這個(gè)控制器中使用另一個(gè)存儲(chǔ)庫。我試圖像這樣但失敗了。$anotherRepo?=?new?AnotherRepo();?//?I?think?AnotherRepo`?is?interface.我打算獲取$anotherRepo->all()數(shù)據(jù)但無法獲取$anotherRepo實(shí)例。請(qǐng)幫助我如何獲取存儲(chǔ)庫實(shí)例。
如何獲取存儲(chǔ)庫實(shí)例?
長風(fēng)秋雁
2023-05-26 14:24:49