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

  • <legend id='sgxOb'><style id='sgxOb'><dir id='sgxOb'><q id='sgxOb'></q></dir></style></legend>

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

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

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

        自動注入的 Laravel 模型沒有屬性

        auto-injected Laravel model has no attributes(自動注入的 Laravel 模型沒有屬性)

            <tbody id='aLu49'></tbody>

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

            <tfoot id='aLu49'></tfoot>

                • <bdo id='aLu49'></bdo><ul id='aLu49'></ul>
                  本文介紹了自動注入的 Laravel 模型沒有屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我是 Laravel 的新手.我已經為我的一個表創建了一個模型、一個資源控制器和一個路由,我修改了模型類以使用特定的表名,但是 Laravel 5.4 注入的模型對象沒有屬性,即使相應的記錄存在于數據庫.這是我采取的步驟.

                  I'm new to Laravel. I have created a model, a resource controller, and a route for one of my tables, I have modified the model class to use a particular table name, but the model object injected by Laravel 5.4 has no attributes even though a corresponding record exists in the database. Here are the steps I took.

                  1) 使用工匠創建模型.我運行了這個命令:

                  1) Create the model with artisan. I ran this command:

                  php artisan make:model Tree
                  

                  2) 將 Tree 模型類修改為 instructed 以指定特定表.我必須這樣做,因為我的表被命名為 tree,而不是 Laravel 根據其內部規則假設的樹".

                  2) Modify the Tree model class as instructed to specify a specific table. I had to do this because my table is named tree, not the "trees" as Laravel would otherwise assume based on its internal rules.

                  /**
                   * The table associated with the model.
                   *
                   * @var string
                   */
                  protected $table = 'tree';
                  

                  3) 創建一個資源控制器,通過這個命令使用我的模型

                  3) Create a resource controller that makes use of my model with this command

                  php artisan make:controller CategoryController --resource --model=Tree
                  

                  4) 添加資源路由 routes/web.php 以將 Web 服務器路徑映射到控制器:

                  4) Add a resource route routes/web.php in order to map a web server path onto the controller:

                  Route::resource('categories', 'CategoryController');
                  

                  5) 修改 CategoryController 的 show() 方法,以 var_dump 注入的 $tree 對象.它看起來像這樣:

                  5) Modify the show() method of the CategoryController to var_dump the injected $tree object. It looks like this:

                  /**
                   * Display the specified resource.
                   *
                   * @param  AppTree  $tree
                   * @return IlluminateHttpResponse
                   */
                  public function show(Tree $tree)
                  {
                      // we need to display the children of $tree
                      var_dump($tree);
                  
                  }
                  

                  6) 我的表結構遵循 Laravel 文檔指定的所有約定.有一個整數 id 列是無符號的 &自動遞增.我有 created_at 和 updated_at 時間戳.唯一不同的是表名是樹"而不是樹",但這應該包含在我上面所做的更改中:

                  6) My table structure follows all the conventions specified by Laravel docs. There is an integer id column that is unsigned & auto-incrementing. I have the created_at and updated_at timestamps. The only thing different is that the table name is "tree" and not "trees", but that should be covered with the change I made above:

                  CREATE TABLE IF NOT EXISTS `tree` (
                    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
                    `parent_id` int(10) unsigned DEFAULT NULL,
                    `label` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
                    `display_order` int(11) unsigned NOT NULL DEFAULT '0',
                    `forum_id` int(5) NOT NULL DEFAULT '0',
                    `url` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
                    `flavor` tinyint(4) NOT NULL DEFAULT '0',
                    `created_at` timestamp NULL DEFAULT NULL,
                    `updated_at` timestamp NULL DEFAULT NULL,
                    PRIMARY KEY (`id`),
                    KEY `parent_pkey` (`parent_id`)
                  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
                  

                  此表包含數據.它絕對有一個 id=1 的記錄.

                  This table contains data. It most definitely has a record with id=1.

                  7) 我訪問了應該激活我的資源控制器的 show() 方法的 url.我得到的輸出證實這實際上是 CategoryController::show() 方法.http://example.com/categories/1

                  7) I visit the url which should activate the show() method of my resource controller. The output I get verfies that this is in fact the method CategoryController::show(). http://example.com/categories/1

                  問題來了.

                  var_dump($tree) 的輸出沒有屬性.沒有錯誤,但注入的對象有問題.

                  object(AppTree)#217 (24) {
                    ["table":protected]=>
                    string(4) "tree"
                    ["connection":protected]=>
                    NULL
                    ["primaryKey":protected]=>
                    string(2) "id"
                    ["keyType":protected]=>
                    string(3) "int"
                    ["incrementing"]=>
                    bool(true)
                    ["with":protected]=>
                    array(0) {
                    }
                    ["perPage":protected]=>
                    int(15)
                    ["exists"]=>
                    bool(false)
                    ["wasRecentlyCreated"]=>
                    bool(false)
                    ["attributes":protected]=>
                    array(0) {
                    }
                    ["original":protected]=>
                    array(0) {
                    }
                    ["casts":protected]=>
                    array(0) {
                    }
                    ["dates":protected]=>
                    array(0) {
                    }
                    ["dateFormat":protected]=>
                    NULL
                    ["appends":protected]=>
                    array(0) {
                    }
                    ["events":protected]=>
                    array(0) {
                    }
                    ["observables":protected]=>
                    array(0) {
                    }
                    ["relations":protected]=>
                    array(0) {
                    }
                    ["touches":protected]=>
                    array(0) {
                    }
                    ["timestamps"]=>
                    bool(true)
                    ["hidden":protected]=>
                    array(0) {
                    }
                    ["visible":protected]=>
                    array(0) {
                    }
                    ["fillable":protected]=>
                    array(0) {
                    }
                    ["guarded":protected]=>
                    array(1) {
                      [0]=>
                      string(1) "*"
                    }
                  }
                  

                  我做錯了嗎?如何讓 Laravel 注入正??確的對象?

                  有人問我為什么在我的路線中注入了錯誤的對象.這是在步驟 #3 中自動生成的類的縮寫版本.它清楚地引用了 Tree 類和它期望一個樹對象的代碼提示.除了 var_dump 語句之外,我沒有創建任何這些代碼.它都是按照文檔的指示由工匠命令自動生成的.

                  Someone asked why I was injecting the wrong object in my route. Here is an abbreviated version of the class that was auto-generated in step #3. It clear references the Tree class and code-hints it is expecting a tree object. I did not create any of this code except the var_dump statement. It was all auto-generated by artisan commands expressly as instructed by the docs.

                  namespace AppHttpControllers;
                  
                  use AppTree;
                  use IlluminateHttpRequest;
                  
                  class CategoryController extends Controller
                  {
                  
                      /**
                       * Display the specified resource.
                       *
                       * @param  AppTree  $tree
                       * @return IlluminateHttpResponse
                       */
                      public function show(Tree $tree)
                      {
                          // we need to display the children of $tree
                          var_dump($tree);
                  
                      }
                  
                  }
                  

                  推薦答案

                  Route Model 綁定有一個命名約定.

                  There is a naming convention on Route Model binding.

                  嘗試將操作調用更改為:

                  Try to change the action call to this:

                  public function show(Tree $category)
                  {
                      var_dump($category);
                  }
                  

                  更新:我查看了源代碼,您也可以更改資源路由聲明中的參數名稱:

                  Update: I looked in the source and you can also change the parameters name in resource Route declaration:

                  Route::resource('categories', 'CategoryController', ['parameters'=>['categories'=>'tree']]);
                  

                  并在動作調用中使用 $tree 變量

                  And use the $tree variable in action call

                  public function show(Tree $tree)
                  

                  這篇關于自動注入的 Laravel 模型沒有屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)

                    <bdo id='aIaqB'></bdo><ul id='aIaqB'></ul>
                  • <tfoot id='aIaqB'></tfoot>
                      <tbody id='aIaqB'></tbody>

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

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

                          <legend id='aIaqB'><style id='aIaqB'><dir id='aIaqB'><q id='aIaqB'></q></dir></style></legend>
                            主站蜘蛛池模板: 选宝石船-陆地水上开采「精选」色选机械设备-青州冠诚重工机械有限公司 | ISO9001认证咨询_iso9001企业认证代理机构_14001|18001|16949|50430认证-艾世欧认证网 | 喷码机,激光喷码打码机,鸡蛋打码机,手持打码机,自动喷码机,一物一码防伪溯源-恒欣瑞达有限公司 | 论文查重_免费论文查重_知网学术不端论文查重检测系统入口_论文查重软件 | 温湿度记录纸_圆盘_横河记录纸|霍尼韦尔记录仪-广州汤米斯机电设备有限公司 | SDI车窗夹力测试仪-KEMKRAFT方向盘测试仪-上海爱泽工业设备有限公司 | 山东led显示屏,山东led全彩显示屏,山东LED小间距屏,临沂全彩电子屏-山东亚泰视讯传媒有限公司 | 探伤仪,漆膜厚度测试仪,轮胎花纹深度尺厂家-淄博创宇电子 | 广东泵阀展|阀门展-广东国际泵管阀展览会 | 广东西屋电气有限公司-广东西屋电气有限公司 | 国产离子色谱仪,红外分光测油仪,自动烟尘烟气测试仪-青岛埃仑通用科技有限公司 | 手术室净化厂家_成都实验室装修公司_无尘车间施工单位_洁净室工程建设团队-四川华锐16年行业经验 | 箱式破碎机_移动方箱式破碎机/价格/厂家_【华盛铭重工】 | 高精度电阻回路测试仪-回路直流电阻测试仪-武汉特高压电力科技有限公司 | 广州食堂承包_广州团餐配送_广州堂食餐饮服务公司 - 旺记餐饮 | 螺旋叶片_螺旋叶片成型机_绞龙叶片_莱州源泽机械制造有限公司 | 江苏大隆凯科技有限公司| 滁州高低温冲击试验箱厂家_安徽高低温试验箱价格|安徽希尔伯特 | 气动|电动调节阀|球阀|蝶阀-自力式调节阀-上海渠工阀门管道工程有限公司 | 恒温恒湿试验箱_高低温试验箱_恒温恒湿箱-东莞市高天试验设备有限公司 | 玖容气动液压设备有限公司-气液增压缸_压力机_增压机_铆接机_增压器 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 | 交通气象站_能见度检测仪_路面状况监测站- 天合环境科技 | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 焊接烟尘净化器__焊烟除尘设备_打磨工作台_喷漆废气治理设备 -催化燃烧设备 _天津路博蓝天环保科技有限公司 | 专业深孔加工_东莞深孔钻加工_东莞深孔钻_东莞深孔加工_模具深孔钻加工厂-东莞市超耀实业有限公司 | 室内室外厚型|超薄型|非膨胀型钢结构防火涂料_隧道专用防火涂料厂家|电话|价格|批发|施工 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 仿真植物|仿真树|仿真花|假树|植物墙 - 广州天昆仿真植物有限公司 | 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 真空干燥烘箱_鼓风干燥箱 _高低温恒温恒湿试验箱_光照二氧化碳恒温培养箱-上海航佩仪器 | 百方网-百方电气网,电工电气行业专业的B2B电子商务平台 | 工业插头-工业插头插座【厂家】-温州罗曼电气 | 桨叶搅拌机_螺旋挤压/方盒旋切造粒机厂家-无锡市鸿诚输送机械有限公司 | 上海平衡机-单面卧式动平衡机-万向节动平衡机-圈带动平衡机厂家-上海申岢动平衡机制造有限公司 | 施工电梯_齿条货梯_烟囱电梯_物料提升机-河南大诚机械制造有限公司 | 保定市泰宏机械制造厂-河北铸件厂-铸造厂-铸件加工-河北大件加工 | PU树脂_水性聚氨酯树脂_聚氨酯固化剂_聚氨酯树脂厂家_宝景化工 | 山东集装箱活动房|济南集装箱活动房-济南利森集装箱有限公司 | 税筹星_灵活用工平台_企业财务顾问_财税法薪综合服务平台 |