久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='AARES'><style id='AARES'><dir id='AARES'><q id='AARES'></q></dir></style></legend>
  • <tfoot id='AARES'></tfoot>

        <bdo id='AARES'></bdo><ul id='AARES'></ul>

        <i id='AARES'><tr id='AARES'><dt id='AARES'><q id='AARES'><span id='AARES'><b id='AARES'><form id='AARES'><ins id='AARES'></ins><ul id='AARES'></ul><sub id='AARES'></sub></form><legend id='AARES'></legend><bdo id='AARES'><pre id='AARES'><center id='AARES'></center></pre></bdo></b><th id='AARES'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AARES'><tfoot id='AARES'></tfoot><dl id='AARES'><fieldset id='AARES'></fieldset></dl></div>

        <small id='AARES'></small><noframes id='AARES'>

      1. Laravel Eloquent ORM 中的多租戶

        Multi tenancy in Laravel Eloquent ORM(Laravel Eloquent ORM 中的多租戶)

        <legend id='9MFNB'><style id='9MFNB'><dir id='9MFNB'><q id='9MFNB'></q></dir></style></legend>
        <i id='9MFNB'><tr id='9MFNB'><dt id='9MFNB'><q id='9MFNB'><span id='9MFNB'><b id='9MFNB'><form id='9MFNB'><ins id='9MFNB'></ins><ul id='9MFNB'></ul><sub id='9MFNB'></sub></form><legend id='9MFNB'></legend><bdo id='9MFNB'><pre id='9MFNB'><center id='9MFNB'></center></pre></bdo></b><th id='9MFNB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9MFNB'><tfoot id='9MFNB'></tfoot><dl id='9MFNB'><fieldset id='9MFNB'></fieldset></dl></div>

            • <bdo id='9MFNB'></bdo><ul id='9MFNB'></ul>
              <tfoot id='9MFNB'></tfoot>

                  <small id='9MFNB'></small><noframes id='9MFNB'>

                    <tbody id='9MFNB'></tbody>

                  本文介紹了Laravel Eloquent ORM 中的多租戶的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這是來自

                  強制 Eloquent 模型重新解析數據庫連接

                  有多個數據庫連接:

                  return [
                      'default' => 'mysql-key1',
                      'connections' => [
                          'mysql-key1' => [
                              'driver'    => 'mysql',
                              'database'  => 'key1_dbname,
                              // etc
                          ],
                          'mysql-key2' => [
                              'driver'    => 'mysql',
                              'database'  => 'key2_dbname',
                              // etc
                          ]
                      ]
                  ];
                  

                  我有一個使用模型 setConnection 更改連接屬性的產品存儲庫:

                  I have a product repository which uses the Model setConnection to change the connection attribute :

                  public function setConnection($name) {
                      // assumes $this->product is your Product model
                      $this->product->setConnection($name);
                  }
                  

                  然而,我發現它只適用于查詢方法,而不適用于 Model::create ::

                  However, i found out that it only worked on query methods and not methods like Model::create ::

                  $productRepo = new ProductRepository();
                  foreach ($array as $key => $value) {
                     $productRepo->setConnection($key . '_' . $database);
                     // this works
                     $products = $productRepo->all();
                     // this doesn't work and will use the old connection 
                     $product = $productRepo->create($data); 
                  }
                  

                  似乎一旦創建了實例,::create 方法就不會解析連接.有人知道修復嗎?

                  Seems that the ::create method does not resolve the connection once the instance has been created. Anyone knows a fix?

                  推薦答案

                  問題是 setConnection() 作用于一個類的實例,但是 create()> 方法是類本身的靜態方法.在您的存儲庫中,$this->product 是 Product 類的一個實例.在執行查詢之前在此實例上使用 setConnection() 會正常工作,但是如果您想在靜態方法上使用單獨的連接(例如 create()).

                  The problem is that setConnection() works on an instance of a class, but the create() method is a static method on the class itself. In your repository, $this->product is an instance of the Product class. Using setConnection() on this instance before doing queries will work fine, but you'll need to do a little more manual work if you want to use separate connections on the static methods (such as create()).

                  create() 方法所做的就是用給定的屬性實例化一個新實例,然后調用 save().因此,無需在 Product 模型上調用 create(),您只需手動執行此操作:

                  All the create() method does is instantiate a new instance with the given attributes and then call save(). So, instead of calling create() on the Product model, you'll just need to do this manually:

                  class ProductRepository {
                      public function create(array $attributes, $connection = null) {
                          $product = $this->product->newInstance($attributes);
                          $product->setConnection($connection ?: $this->product->getConnectionName());
                          $product->save();
                          return $product;
                      }
                  }
                  

                  您還可以覆蓋 Product 模型上的靜態 create() 方法以接受連接.

                  You could also override the static create() method on the Product model to accept a connection, as well.

                  class Product extends Model {
                      public static function create(array $attributes, $connection = null) {
                          $model = new static($attributes);
                          $model->setConnection($connection ?: $this->connection);
                          $model->save();
                          return $model;
                      }
                  }
                  
                  class ProductRepository {
                      public function create(array $attributes, $connection = null) {
                          $connection = $connection ?: $this->product->getConnectionName()
                          return $this->product->create($attributes, $connection);
                      }
                  }
                  

                  這篇關于Laravel Eloquent ORM 中的多租戶的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

                  <small id='Tb6SW'></small><noframes id='Tb6SW'>

                    <tfoot id='Tb6SW'></tfoot>
                    <i id='Tb6SW'><tr id='Tb6SW'><dt id='Tb6SW'><q id='Tb6SW'><span id='Tb6SW'><b id='Tb6SW'><form id='Tb6SW'><ins id='Tb6SW'></ins><ul id='Tb6SW'></ul><sub id='Tb6SW'></sub></form><legend id='Tb6SW'></legend><bdo id='Tb6SW'><pre id='Tb6SW'><center id='Tb6SW'></center></pre></bdo></b><th id='Tb6SW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Tb6SW'><tfoot id='Tb6SW'></tfoot><dl id='Tb6SW'><fieldset id='Tb6SW'></fieldset></dl></div>

                          <tbody id='Tb6SW'></tbody>

                          <bdo id='Tb6SW'></bdo><ul id='Tb6SW'></ul>
                          <legend id='Tb6SW'><style id='Tb6SW'><dir id='Tb6SW'><q id='Tb6SW'></q></dir></style></legend>
                            主站蜘蛛池模板: 亚洲精品66| 一区二区三区欧美大片 | 一本一道久久a久久精品蜜桃 | 国产午夜亚洲精品不卡 | 亚洲午夜在线 | 精品一区二区三区免费视频 | 久久人体视频 | 美女久久久久久久 | 国产乱码精品一区二区三区中文 | 久久中文免费视频 | 国产日产精品一区二区三区四区 | 国产做爰 | 中文字幕在线免费观看 | 在线观看av不卡 | 青青操av | 国产成人精品一区二区三区四区 | 国产成人精品综合 | 日本人和亚洲人zjzjhd | 日韩精品视频在线观看一区二区三区 | 久草久草久草 | 一区二区视频在线 | 亚洲一区中文字幕 | av中文天堂 | 日日摸夜夜添夜夜添特色大片 | 国产午夜精品久久久久免费视高清 | 国产免费又黄又爽又刺激蜜月al | 欧美久久久久久 | 高清一区二区视频 | 成人在线观 | 深爱激情综合 | 午夜小视频免费观看 | 羞羞视频在线网站观看 | 亚洲日韩中文字幕一区 | 日本午夜网 | 久久久国| 高清久久久 | 欧美精品片 | 99国产精品一区二区三区 | 不卡在线视频 | 五月婷婷婷 | 国产精品亚洲精品 |