【发布时间】:2015-02-19 06:40:59
【问题描述】:
我正在尝试访问我的一个表的 id 列,但出现“未定义属性”错误,但我可以毫无问题地访问其他列,这是我的代码 在控制器中,我得到所有记录如下
$employees=Employee::all();
return View::make('admin.employee',compact('tittle','heading','employees'));
我的看法
@foreach($employees as $employee)
<tr class="success">
<td><a href="">{{$employee->first_name}}</a></td>
<td>{{$employee->last_name}}</td>
<td>{{$employee->phone}}</td>
<td>{{$employee->salary}}</td>
<td>{{$employee->created_at}}</td>
<td><a href="{{URL::route('employee.view',array($employee->id))}}" class="btn btn-primary btn-xs">Edit</a></td>
<td><a href="#" class="btn btn-success btn-xs">Resign</a></td>
<td><a href="#" class="btn btn-warning btn-xs">View</a></td>
</tr>
@endforeach
如何从我的表中访问 id 列? 当我 print_r($employees);
Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => Employee Object ( [fillable:protected] => Array ( [0] => profile_photo_id [1] => first_name [2] => last_name [3] => gender [4] => phone [5] => address [6] => age [7] => salary ) [connection:protected] => [table:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array ( [id] => 4 [profile_photo_id] => 4 [first_name] => Jason [last_name] => cbvc [gender] => Female [phone] => 2147483647 [address] => jhjhjh [age] => 12 [salary] => 5566556 [created_at] => 2014-12-20 11:29:41 [updated_at] => 2014-12-20 11:29:41 ) [original:protected] => Array ( [id] => 4 [profile_photo_id] => 4 [first_name] => Jason [last_name] => cbvc [gender] => Female [phone] => 2147483647 [address] => jhjhjh [age] => 12 [salary] => 5566556 [created_at] => 2014-12-20 11:29:41 [updated_at] => 2014-12-20 11:29:41 ) [relations:protected] => Array ( ) [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [appends:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) [dates:protected] => Array ( ) [touches:protected] => Array ( ) [observables:protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [exists] => 1 ) [1] => Employee Object ( [fillable:protected] => Array ( [0] => profile_photo_id [1] => first_name [2] => last_name [3] => gender [4] => phone [5] => address [6] => age [7] => salary ) [connection:protected] => [table:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array ( [id] => 5 [profile_photo_id] => 5 [first_name] => gugu [last_name] => cbvc [gender] => Female [phone] => 2147483647 [address] => jhjhjh [age] => 12 [salary] => 5566556 [created_at] => 2014-12-20 11:40:44 [updated_at] => 2014-12-20 11:40:44 ) [original:protected] => Array ( [id] => 5 [profile_photo_id] => 5 [first_name] => gugu [last_name] => cbvc [gender] => Female [phone] => 2147483647 [address] => jhjhjh [age] => 12 [salary] => 5566556 [created_at] => 2014-12-20 11:40:44 [updated_at] => 2014-12-20 11:40:44 ) [relations:protected] => Array ( ) [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [appends:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) [dates:protected] => Array ( ) [touches:protected] => Array ( ) [observables:protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [exists] => 1 ) ) )
【问题讨论】: