2014-12-20 2 views
-1

Я пытаюсь получить доступ к столбцу id одной из моих таблиц, но я получаю «Неопределенное свойство», но я могу получить доступ к другим столбцам без проблем, здесь мой код в контроллере я получаю все записи следующим образомЯ не могу получить доступ к столбцу 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 из моей таблицы? , когда i 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))) 

ответ

0

Дайте нам ваши $ сотрудники объект, редактировать вопрос с

print_r($employees). 

Также может быть шанс $ ID защищен, в этом случае использование.

$employee->getOriginal('id'); 
+0

$ employee-> getOriginal ('id'); работал!!!! благодаря – Malouda