亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取存儲庫實例?

如何獲取存儲庫實例?

PHP
長風秋雁 2023-05-26 14:24:49
我在 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。


查看完整回答
反對 回復 2023-05-26
  • 1 回答
  • 0 關注
  • 171 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號