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

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

laravel repository 求解?

laravel repository 求解?

PHP
慕慕森 2019-03-14 18:41:19
假設:通過配置文件可以切換數據存儲驅動,比如數據存放在 mysql,然后修改配置文件變為 redis。目前我的偽代碼如下: 1:建立一個接口 <?php namespace App\Repositories\Interfaces; Interface CategoryInterface { public function getAll(); public function setData(); } 2:建立兩個 Repository,分別對應mysql,redis數據庫操作。 <?php namespace App\Repositories\Implement; use App\Repositories\Interfaces\CategoryInterface; class CategoryMysqlRepository implements CategoryInterface { public function getAll() { // TODO: Implement getAll() method. } public function setData() { // TODO: Implement setData() method. } } <?php namespace App\Repositories\Implement; use App\Repositories\Interfaces\CategoryInterface; class CategoryRedisRepository implements CategoryInterface { public function getAll() { // TODO: Implement getAll() method. } public function setData() { // TODO: Implement setData() method. } } 3:進行綁定 <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // } /** * Register any application services. * * @return void */ public function register() { $this->app->bind('App\Repositories\Interfaces\CategoryInterface', 'App\Repositories\Implement\CategoryMysqlRepository'); } } 如何更改綁定方式,達到上述目的。謝謝。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 548 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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