pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    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="r5v5nzf" 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="soy4a44" 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="w2ygwm0" 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>
                            主站蜘蛛池模板: 湖南长沙商标注册专利申请,长沙公司注册代理记账首选美创! | 真空上料机(一种真空输送机)-百科 | 国产液相色谱仪-超高效液相色谱仪厂家-上海伍丰科学仪器有限公司 | 塑胶跑道_学校塑胶跑道_塑胶球场_运动场材料厂家_中国塑胶跑道十大生产厂家_混合型塑胶跑道_透气型塑胶跑道-广东绿晨体育设施有限公司 | 北京四合院出租,北京四合院出售,北京平房买卖 - 顺益兴四合院 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 玻璃钢罐_玻璃钢储罐_盐酸罐厂家-河北华盛节能设备有限公司 | HDPE储罐_厂家-山东九州阿丽贝防腐设备 | 不锈钢螺丝,不锈钢螺栓,不锈钢标准件-江苏百德特种合金有限公司 交变/复合盐雾试验箱-高低温冲击试验箱_安奈设备产品供应杭州/江苏南京/安徽马鞍山合肥等全国各地 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | SMC-ASCO-CKD气缸-FESTO-MAC电磁阀-上海天筹自动化设备官网 | 散热器-电子散热器-型材散热器-电源散热片-镇江新区宏图电子散热片厂家 | 合肥汽车充电桩_安徽充电桩_电动交流充电桩厂家_安徽科帝新能源科技有限公司 | 湖北省煤炭供应链综合服务平台| 阴离子_阳离子聚丙烯酰胺厂家_聚合氯化铝价格_水处理絮凝剂_巩义市江源净水材料有限公司 | 老房子翻新装修,旧房墙面翻新,房屋防水补漏,厨房卫生间改造,室内装潢装修公司 - 一修房屋快修官网 | 合肥网带炉_安徽箱式炉_钟罩炉-合肥品炙装备科技有限公司 | CE认证_FCC认证_CCC认证_MFI认证_UN38.3认证-微测检测 CNAS实验室 | 丽陂特官网_手机信号屏蔽器_Wifi信号干扰器厂家_学校考场工厂会议室屏蔽仪 | 活动策划,舞台搭建,活动策划公司-首选美湖上海活动策划公司 | 连续密炼机_双转子连续密炼机_连续式密炼机-南京永睿机械制造有限公司 | 南京泽朗生物科技有限公司-液体饮料代加工_果汁饮料代加工_固体饮料代加工 | 杭州高温泵_热水泵_高温油泵|昆山奥兰克泵业制造有限公司 | 检验科改造施工_DSA手术室净化_导管室装修_成都特殊科室建设厂家_医疗净化工程公司_四川华锐 | 巩义市科瑞仪器有限公司| 飞利浦LED体育场灯具-吸顶式油站灯-飞利浦LED罩棚灯-佛山嘉耀照明有限公司 | 华夏医界网_民营医疗产业信息平台_民营医院营销管理培训 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 单螺旋速冻机-双螺旋-流态化-隧道式-食品速冻机厂家-广州冰泉制冷 | 无锡门窗-系统门窗-阳光房-封阳台-断桥铝门窗厂[窗致美] | 防火板_饰面耐火板价格、厂家_品牌认准格林雅 | 工控机,嵌入式主板,工业主板,arm主板,图像采集卡,poe网卡,朗锐智科 | 济南铝方通-济南铝方通价格-济南方通厂家-山东鲁方通建材有限公司 | 传动滚筒,改向滚筒-淄博建凯机械科技有限公司 | 不锈钢复合板|钛复合板|金属复合板|南钢集团安徽金元素复合材料有限公司-官网 | 亿立分板机_曲线_锯片式_走刀_在线式全自动_铣刀_在线V槽分板机-杭州亿协智能装备有限公司 | 纸箱网 -纸箱机械|设备|包装纸盒|包装印刷行业门户网站 | 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 刮板输送机,粉尘加湿搅拌机,螺旋输送机,布袋除尘器 | 风化石头制砂机_方解石制砂机_瓷砖石子制砂机_华盛铭厂家 | 最新范文网_实用的精品范文美文网 |