【发布时间】:2018-04-12 08:06:52
【问题描述】:
在修复我刚刚输入的新代码后,我不断收到此错误,我不知道为什么它给我这个错误“属性 [id] 在此集合实例上不存在”,它指向 id我在 home.blade.php 中的路线。谁能帮我看看 非常感谢
我添加的部分是hire_status部分,在修复它之后,它给了我这个错误。 home.blade.php
<table class="table table-bordered">
<tr>
<th><strong><big>Name: </big></strong></th>
<th><strong><big>Hire Status: </big></strong></th>
<th><strong><big>Action: </big></strong></th>
</tr>
<td>
<tr>
@foreach($data as $value)
<tr>
<th><a href="{{route('user.show',['id'=>$value->id])}}">{{$value->Name}}</a></th>
<th>
@foreach($data1 as $value1)
{{$value1->hire_status}}
</th>
<th><form action="{{ url('/home/'.$value->id.'/delete') }}" method="get">
{{ csrf_field() }}
<button type="submit">Delete</button>
</form></th>
</tr>
@endforeach
@endforeach
</tr>
</tr>
</table>
家庭控制器:
public function getData(){
$data['data'] = DB::table('personal_infos')->where('deleted_at',NULL)->get()->sortByDesc('created_at');
$data1 = DB::table('hires')->where('hire_status','Yes')->get();
if(count($data)>0){
return view('home',compact('data','data1'));
}else{
return view('home');
}
}
【问题讨论】:
-
print_r 你的 $data,我们可以看到你的 $data 包含吗?
-
@Rits 对不起,我把 print_r 放在哪里,对不起,我第一次使用它
-
只是,print_r() 在这个
$data['data'] = DB::table('personal_infos')->where('deleted_at',NULL)->get()->sortByDesc('created_at');print_r($data) 之后;退出; -
你为什么要把数组(键)数据删除,然后只用 $data = DB::table('personal_infos')->where('deleted_at',NULL) 检查它->get()->sortByDesc('created_at');
-
@Rits 我已经完成了 print_r,它包含了我保存在数据库中的所有数据,其中包含多个数组,例如数组 [0] 和数组 [1]