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

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

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

      1. <tfoot id='YbqnQ'></tfoot>
        <legend id='YbqnQ'><style id='YbqnQ'><dir id='YbqnQ'><q id='YbqnQ'></q></dir></style></legend>

      2. 此集合實例上不存在屬性 [名稱]

        Property [name] does not exist on this collection instance(此集合實例上不存在屬性 [名稱])

              • <bdo id='1Yii7'></bdo><ul id='1Yii7'></ul>

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

                • <small id='1Yii7'></small><noframes id='1Yii7'>

                    <tbody id='1Yii7'></tbody>
                  <tfoot id='1Yii7'></tfoot>
                • 本文介紹了此集合實例上不存在屬性 [名稱]的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在數據庫中有 3 個表(用戶、區域、區域用戶),

                  用戶表:ID名稱用戶名密碼

                  區域表:ID姓名

                  area_user 表:ID用戶身份area_id

                  我正在嘗試創建一個(列出用戶頁面),它將顯示所有用戶表列以及用戶分配的區域.

                  User.php 模型文件

                   belongsToMany('AppArea','area_user');}

                  Area.php 模型文件:

                  belongsToMany('AppUser','area_user','area_id','user_id');}}

                  UserController@index 文件:

                  middleware('auth');}/*** 顯示資源列表.** @return IlluminateHttpResponse*/公共函數索引(){$users = User::get();return view('users._list',['用戶'=>$用戶]);}

                  最后是表格視圖文件:-

                  @foreach($users as $u)<tr role="row" class="odd"><td class="sorting_1">{{$u->name}}</td><td></td><td>{{$u->areas]}}</td><td>{{route('show_user', ['id' => $u->id])}}</td></tr></tbody>@endforeach

                  如果我只使用區域屬性 ($u->areas) 在用戶表視圖(指定區域)中輸入,它將顯示所有區域列:-

                  <預><代碼>[{身份證":3,"name": "C",location_id":1,created_at":空,updated_at":空,樞軸":{"user_id": 4,area_id":3}},{身份證":4,"name": "D",location_id":2,created_at":空,updated_at":空,樞軸":{"user_id": 4,area_id":4}}]

                  <小時>

                   @foreach($users as $u)<tr role="row" class="odd"><td class="sorting_1">{{$u->name}}</td><td></td><td>{{$u->areas->name]}}</td><td>{{route('show_user', ['id' => $u->id])}}</td></tr></tbody>@endforeach

                  請注意,如果我在上面的視圖 ($u->areas->name) 中指定區域關系中的列名,則顯示錯誤:-

                  此集合實例上不存在屬性 [名稱].(查看:C:xampphtdocs

                  如何在視圖文件中只顯示(areas.name)列

                  解決方案

                  因為 areas 是一個集合,所以你應該像這樣循環:

                  @foreach($users as $u)<tr role="row" class="odd"><td class="sorting_1">{{$u->name}}</td><td></td><td>@foreach($u->areas as $area){{$area->name}},@endforeach</td><td>{{route('show_user', ['id' => $u->id])}}</td></tr></tbody>@endforeach

                  如果你想用逗號分隔它們,你可以這樣做而無需循環:

                   @foreach($users as $u)<tr role="row" class="odd"><td class="sorting_1">{{$u->name}}</td><td></td><td>{{ $u->areas->pluck('name')->implode(', ') }}</td><td>{{route('show_user', ['id' => $u->id])}}</td></tr></tbody>@endforeach

                  I have 3 tables in DB (users , areas , area_user),

                  Users table: id name username password

                  areas table: id name

                  area_user table: id user_id area_id

                  I am trying to create a (List users page) which will show all user table column with user assigned areas.

                  User.php Model file

                    <?php
                  
                  namespace App;
                  
                  use IlluminateNotificationsNotifiable;
                  use IlluminateFoundationAuthUser as Authenticatable;
                  
                  class User extends Authenticatable{
                      use Notifiable;
                  
                      /**
                       * The attributes that are mass assignable.
                       *
                       * @var array
                       */
                      protected $fillable = ['name', 'email', 'password','role_id',];
                  
                      /**
                       * The attributes that should be hidden for arrays.
                       *
                       * @var array
                       */
                      protected $hidden = ['password', 'remember_token',];
                  
                      public function areas(){
                          return $this->belongsToMany('AppArea','area_user');
                      }
                  

                  Area.php Model file:

                  <?php
                  
                  namespace App;
                  
                  use IlluminateDatabaseEloquentModel;
                  
                  class Area extends Model{
                      protected $fillable = ['name'];
                  
                      public function users(){
                          return $this->belongsToMany('AppUser','area_user','area_id','user_id');
                      }
                  }
                  

                  UserController@index file :

                  <?php
                  
                  namespace AppHttpControllers;
                  
                  use AppAreas;
                  use AppRoles;
                  use AppUser;
                  use IlluminateHttpRequest;
                  
                  class UserController extends Controller{
                  
                      public function __construct(){
                          // $this->middleware('auth');
                      }
                  
                      /**
                       * Display a listing of the resource.
                       *
                       * @return IlluminateHttpResponse
                       */
                      public function index(){
                          $users = User::get();
                          return view('users._list',
                          ['users'=> $users]
                      );
                      }
                  

                  Finally the table view file:-

                  @foreach($users as $u)
                              <tr role="row" class="odd">
                                  <td class="sorting_1">{{$u->name}}</td>
                                  <td></td>
                                  <td>{{$u->areas]}}</td>
                                  <td>{{route('show_user', ['id' => $u->id])}}</td>
                              </tr></tbody>
                  @endforeach
                  

                  If i typed in user table view (assigned areas) with only using the areas property ($u->areas), it will show all the areas column:-

                  [
                    {
                      "id": 3,
                      "name": "C",
                      "location_id": 1,
                      "created_at": null,
                      "updated_at": null,
                      "pivot": {
                        "user_id": 4,
                        "area_id": 3
                      }
                    },
                    {
                      "id": 4,
                      "name": "D",
                      "location_id": 2,
                      "created_at": null,
                      "updated_at": null,
                      "pivot": {
                        "user_id": 4,
                        "area_id": 4
                      }
                    }
                  ]
                  


                   @foreach($users as $u)
                                  <tr role="row" class="odd">
                                      <td class="sorting_1">{{$u->name}}</td>
                                      <td></td>
                                      <td>{{$u->areas->name]}}</td>
                                      <td>{{route('show_user', ['id' => $u->id])}}</td>
                                  </tr></tbody>
                      @endforeach
                  

                  Notice that if i specify the column name in Areas relationship in the above view ($u->areas->name) , error showing:-

                  Property [name] does not exist on this collection instance. (View: C:xampphtdocs

                  How can i show only the (areas.name) column in view file

                  解決方案

                  Because the areas is a collection so you should loop over it like this :

                  @foreach($users as $u)
                      <tr role="row" class="odd">
                          <td class="sorting_1">{{$u->name}}</td>
                          <td></td>
                          <td>
                          @foreach($u->areas as $area)
                              {{$area->name}}, 
                          @endforeach
                          </td>
                          <td>{{route('show_user', ['id' => $u->id])}}</td>
                      </tr></tbody>
                  @endforeach
                  

                  And if you want to separate them whith comma for example you can do it like that without looping :

                      @foreach($users as $u)
                      <tr role="row" class="odd">
                          <td class="sorting_1">{{$u->name}}</td>
                          <td></td>
                          <td>
                              {{ $u->areas->pluck('name')->implode(', ') }}
                          </td>
                          <td>{{route('show_user', ['id' => $u->id])}}</td>
                      </tr></tbody>
                  @endforeach
                  

                  這篇關于此集合實例上不存在屬性 [名稱]的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)

                    <legend id='4pv63'><style id='4pv63'><dir id='4pv63'><q id='4pv63'></q></dir></style></legend>
                        • <bdo id='4pv63'></bdo><ul id='4pv63'></ul>
                        • <i id='4pv63'><tr id='4pv63'><dt id='4pv63'><q id='4pv63'><span id='4pv63'><b id='4pv63'><form id='4pv63'><ins id='4pv63'></ins><ul id='4pv63'></ul><sub id='4pv63'></sub></form><legend id='4pv63'></legend><bdo id='4pv63'><pre id='4pv63'><center id='4pv63'></center></pre></bdo></b><th id='4pv63'></th></span></q></dt></tr></i><div class="iuiq02i" id='4pv63'><tfoot id='4pv63'></tfoot><dl id='4pv63'><fieldset id='4pv63'></fieldset></dl></div>
                            <tbody id='4pv63'></tbody>

                            <small id='4pv63'></small><noframes id='4pv63'>

                            <tfoot id='4pv63'></tfoot>

                            主站蜘蛛池模板: 电力测功机,电涡流测功机,磁粉制动器,南通远辰曳引机测试台 | 槽钢冲孔机,槽钢三面冲,带钢冲孔机-山东兴田阳光智能装备股份有限公司 | 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | 防火门-专业生产甲级不锈钢钢质防火门厂家资质齐全-广东恒磊安防设备有限公司 | 留学生辅导网-在线课程论文辅导-留学生挂科申诉机构 | 超声波清洗机-超声波清洗设备定制生产厂家 - 深圳市冠博科技实业有限公司 | 聚氨酯复合板保温板厂家_廊坊华宇创新科技有限公司 | 集装箱展厅-住人集装箱住宿|建筑|房屋|集装箱售楼处-山东锐嘉科技工程有限公司 | 太空舱_民宿太空舱厂家_移动房屋太空舱价格-豪品建筑 | 全自动贴标机-套标机-工业热风机-不干胶贴标机-上海厚冉机械 | 威廉希尔WilliamHill·足球(中国)体育官方网站 | 胀套-锁紧盘-风电锁紧盘-蛇形联轴器「厂家」-瑞安市宝德隆机械配件有限公司 | 美的商用净水器_美的直饮机_一级代理经销商_Midea租赁价格-厂家反渗透滤芯-直饮水批发品牌售后 | 丙烷/液氧/液氮气化器,丙烷/液氧/液氮汽化器-无锡舍勒能源科技有限公司 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 | 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | 深圳南财多媒体有限公司介绍 | 维泰克Veertek-锂电池微短路检测_锂电池腐蚀检测_锂电池漏液检测 | 全自动变压器变比组别测试仪-手持式直流电阻测试仪-上海来扬电气 | 换链神器官网-友情链接交换、购买交易于一体的站长平台 | 亮化工程,亮化设计,城市亮化工程,亮化资质合作,长沙亮化照明,杰奥思【官网】 | 钛合金标准件-钛合金螺丝-钛管件-钛合金棒-钛合金板-钛合金锻件-宝鸡远航钛业有限公司 | 小型气象站_便携式自动气象站_校园气象站-竞道气象设备网 | 质检报告_CE认证_FCC认证_SRRC认证_PSE认证_第三方检测机构-深圳市环测威检测技术有限公司 | 百度关键词优化_网站优化_SEO价格 - 云无限好排名 | 六维力传感器_六分量力传感器_模腔压力传感器-南京数智微传感科技有限公司 | 苏州工作服定做-工作服定制-工作服厂家网站-尺品服饰科技(苏州)有限公司 | 北京百度网站优化|北京网站建设公司-百谷网络科技 | 创富网-B2B网站|供求信息网|b2b平台|专业电子商务网站 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 薪动-人力资源公司-灵活用工薪资代发-费用结算-残保金优化-北京秒付科技有限公司 | 层流手术室净化装修-检验科ICU改造施工-华锐净化工程-特殊科室建设厂家 | 压缩空气冷冻式干燥机_吸附式干燥机_吸干机_沪盛冷干机 | 无线联网门锁|校园联网门锁|学校智能门锁|公租房智能门锁|保障房管理系统-KEENZY中科易安 | 酵素生产厂家_酵素OEM_酵素加盟_酵素ODM_酵素原料厂家_厦门益力康 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 加中寰球移民官网-美国移民公司,移民机构,移民中介,移民咨询,投资移民 | 下水道疏通_管道疏通_马桶疏通_附近疏通电话- 立刻通 | 大行程影像测量仪-探针型影像测量仪-增强型影像测量仪|首丰百科 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 |