<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # 簡介 Repository設計模式相當于在控制器層和model層中加了一層,這層是倉庫的意思,存放model層中的一些數據 ![](https://box.kancloud.cn/3bec61da15ecac77370dbeb84102a4b2_1476x478.jpg) # 使用 ![](https://box.kancloud.cn/0bda17b76532c7d366d2da462a7471d1_480x1030.jpg) 建立Repository目錄來存放不同的業務邏輯 在Contracts中存放接口文件,Eloquent中存放具體的實現方法 TestRepository.php ~~~ <?php namespace App\Repository\Test\Eloquent; use App\Repository\Test\Contracts\TestRepositoryInterface; class TestRepository implements TestRepositoryInterface { public function test() { return 'this is test repository'; } } ~~~ TestController.php ~~~ <?php namespace App\Http\Controllers; use App\Http\Requests; use Illuminate\Http\Request; class TestController extends Controller { public function test() { $test = app('Test'); $testInfo = $test->test(); echo $testInfo; } } ~~~ 編寫服務提供者 執行`php artisan make:provider RepositoryServiceProvider ` 編寫你自己的服務提供者 `app\Providers\RepositoryServiceProvider.php`注冊Test倉庫 ~~~ public function register() { $this->registerTestRepository(); } public function provides() { $test = ['Test']; return array_merge($test); } private function registerTestRepository() { $this->app->singleton('Test', 'App\Repository\Test\Eloquent\TestRepository'); } ~~~ 在app.php的providers數組中添加我們的服務提供者 ~~~ 'providers' => [ App\Providers\RepositoryServiceProvider::class, ] ~~~ # 總結 通過這種方式我們可以將不同的業務邏輯分別創建一個倉庫用來存放具體的方法,而在controller層只管調用不用去管具體的實現,也減少了controller層總對數據庫的操作,使代碼更加規范簡潔。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看