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

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

      <tfoot id='lUqKs'></tfoot>

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

        • <bdo id='lUqKs'></bdo><ul id='lUqKs'></ul>

        laravel 雄辯的一對多關系返回 null

        laravel eloquent relation one to many returns null(laravel 雄辯的一對多關系返回 null)

                <bdo id='OFEt7'></bdo><ul id='OFEt7'></ul>
                <legend id='OFEt7'><style id='OFEt7'><dir id='OFEt7'><q id='OFEt7'></q></dir></style></legend>
                <tfoot id='OFEt7'></tfoot>

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

                    <tbody id='OFEt7'></tbody>
                • <i id='OFEt7'><tr id='OFEt7'><dt id='OFEt7'><q id='OFEt7'><span id='OFEt7'><b id='OFEt7'><form id='OFEt7'><ins id='OFEt7'></ins><ul id='OFEt7'></ul><sub id='OFEt7'></sub></form><legend id='OFEt7'></legend><bdo id='OFEt7'><pre id='OFEt7'><center id='OFEt7'></center></pre></bdo></b><th id='OFEt7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='OFEt7'><tfoot id='OFEt7'></tfoot><dl id='OFEt7'><fieldset id='OFEt7'></fieldset></dl></div>
                  本文介紹了laravel 雄辯的一對多關系返回 null的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  當我得到incoming_goods數據(belongsTo)時,產品數據總是返回null.

                  The product data always return null when i get the incoming_goods data (belongsTo).

                  這是我的產品型號:

                  <?php
                  
                  namespace App;
                  
                  use IlluminateDatabaseEloquentModel;
                  use IlluminateDatabaseEloquentSoftDeletes;
                  
                  class Product extends Model
                  {
                      use SoftDeletes;
                  
                      protected $guarded = [
                          'id', 'created_at', 'updated_at', 'deleted_at',
                      ];
                  
                      public function transaction_details()
                      {
                          return $this->hasMany('AppTransaction_detail');
                      }
                  
                      public function incoming_goods()
                      {
                          return $this->hasMany('AppIncoming_good');
                      }       
                  }
                  

                  這是我的 Incoming_good 模型:

                  Here is my Incoming_good Model:

                  <?php
                  
                  namespace App;
                  use IlluminateDatabaseEloquentModel;
                  
                  class Incoming_good extends Model
                  {
                      protected $guarded = [
                          'id', 'created_at', 'updated_at',
                      ];
                  
                      public function product()
                      {
                          return $this->belongsTo('AppProduct');
                      }       
                  }
                  

                  這是我對那兩個表的遷移:

                  And here is my migration of that two table:

                  產品表遷移:

                  <?php
                  
                  use IlluminateSupportFacadesSchema;
                  use IlluminateDatabaseSchemaBlueprint;
                  use IlluminateDatabaseMigrationsMigration;
                  
                  class CreateProductsTable extends Migration
                  {
                      /**
                       * Run the migrations.
                       *
                       * @return void
                       */
                      public function up()
                      {
                          Schema::create('products', function (Blueprint $table) {
                              $table->increments('id');
                              $table->string('name', 50);
                              $table->integer('price');
                              $table->integer('stock')->nullable();
                              $table->integer('available');
                              $table->string('image1', 190)->nullable();
                              $table->string('image2', 190)->nullable();
                              $table->string('image3', 190)->nullable();
                              $table->string('image4', 190)->nullable();
                              $table->string('image5', 190)->nullable();
                              $table->timestamps();
                              $table->softDeletes();
                          });
                      }
                  
                      /**
                       * Reverse the migrations.
                       *
                       * @return void
                       */
                      public function down()
                      {
                          Schema::dropIfExists('products');
                      }
                  }
                  

                  incoming_goods 遷移:

                  incoming_goods migration:

                  <?php
                  
                  use IlluminateSupportFacadesSchema;
                  use IlluminateDatabaseSchemaBlueprint;
                  use IlluminateDatabaseMigrationsMigration;
                  
                  class CreateTableIncomingGoods extends Migration
                  {
                      /**
                       * Run the migrations.
                       *
                       * @return void
                       */
                      public function up()
                      {
                          Schema::create('incoming_goods', function (Blueprint $table) {
                              $table->increments('id');
                              $table->integer('product_id');
                              $table->integer('stock');
                              $table->text('note')->nullable();
                              $table->timestamps();
                          });
                      }
                  
                      /**
                       * Reverse the migrations.
                       *
                       * @return void
                       */
                      public function down()
                      {
                          Schema::dropIfExists('incoming_goods');
                      }
                  }
                  

                  這是我的代碼,用于顯示 incomong_goods 數據和產品(關系屬于):

                  Here is my code to show incomong_goods data and product (relation belongsTo):

                  $data = Incoming_good::select('id', 'stock', 'note', 'created_at')->with('product')->get();
                  

                  我嘗試使用 alies,但它仍然返回 null 的產品數據.希望你能幫助我:)

                  I've try to use alies, but still it return the product data null. Hope you can help me :)

                  推薦答案

                  為了將預先加載的 ProductIncoming_good 相匹配,Laravel 需要外部要選擇的鍵.由于您沒有在選擇列表中包含外鍵 (product_id),Laravel 在檢索它們后無法匹配相關記錄.因此,您所有的 product 關系都將為空.將外鍵添加到選擇列表中,你應該就好了.

                  In order to match up the eager loaded Products with the Incoming_goods, Laravel needs the foreign key to be selected. Since you did not include the foreign key (product_id) in the select list, Laravel can't match up the related records after retrieving them. So, all your product relationships will be empty. Add in the foreign key to the select list, and you should be good.

                  $data = Incoming_good::select('id', 'product_id', 'stock', 'note', 'created_at')
                      ->with('product')
                      ->get();
                  

                  這篇關于laravel 雄辯的一對多關系返回 null的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <tfoot id='uGS2m'></tfoot>

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

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

                          • <bdo id='uGS2m'></bdo><ul id='uGS2m'></ul>
                              <tbody id='uGS2m'></tbody>
                            主站蜘蛛池模板: 精品欧美一区二区在线观看欧美熟 | 国产一区二区三区在线免费观看 | 91一区二区 | av黄色在线 | 九九导航 | 一级女毛片| 中文字幕av网址 | 99福利视频 | 亚洲伊人久久综合 | 成人免费福利视频 | 国产一区二区三区久久久久久久久 | 欧美成人免费在线 | av一级久久| 日韩激情在线 | 四虎永久免费影院 | 欧美日韩视频 | 成人欧美日韩一区二区三区 | 密室大逃脱第六季大神版在线观看 | 日韩在线观看精品 | 久久精品播放 | 国产精品中文 | 综合久久一区 | 国产视频一区二区 | 黄色操视频 | 99成人在线视频 | 婷婷久久综合 | 二区中文字幕 | 国产日韩欧美中文 | 欧美二区三区 | 亚洲欧美在线视频 | 精品一区二区av | 欧美综合一区二区三区 | 夏同学福利网 | 国产精品一区二区不卡 | 久久久性| 婷婷丁香激情 | 日韩一区在线视频 | 日韩中出 | 免费不卡一区 | 日本激情视频网 | 亚洲欧美国产毛片在线 |