我无法访问表格的id列

时间:2014-12-20 14:23:47

标签: mysql laravel laravel-4

我正在尝试访问我的某个表的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 ) ) )

1 个答案:

答案 0 :(得分:0)

$ employees 对象提供给我们,使用

编辑问题
print_r($employees).

$ id 也有可能受到保护,在这种情况下使用。

$employee->getOriginal('id');