我在 Laravel 存儲庫中很新。我正在使用l5-repository 包。當我創建資源控制器時,它創建如下:?public?function?__construct(MyRepository?$repository,?MyValidator?$validator)????{?
????????$this->repository?=?$repository;?
???????????????$this->validator??=?$validator;
????}我可以在這個控制器中獲得MyRepository實例。$this->repository但是我需要在這個控制器中使用另一個存儲庫。我試圖像這樣但失敗了。$anotherRepo?=?new?AnotherRepo();?//?I?think?AnotherRepo`?is?interface.我打算獲取$anotherRepo->all()數據但無法獲取$anotherRepo實例。請幫助我如何獲取存儲庫實例。
1 回答

DIEA
TA貢獻1820條經驗 獲得超2個贊
您只需將它傳遞給構造函數,然后像其他人一樣訪問它。
public function __construct(AnotherRepo $another, MyRepository $repository, MyValidator $validator){ $this->another = $another; $this->repository = $repository; $this->validator = $validator; }
然后得到它$this->another
。
- 1 回答
- 0 關注
- 171 瀏覽
添加回答
舉報
0/150
提交
取消