I have created a relationship between User and Role and it is like One User Belongs To a Role
public function role(){
return $this->belongsTo('App\Role');
}
Now I am trying to access the user role and it is throwing this error
Error:
Trying to get property of non-object
Code For getting User Role:
@foreach($users as $user)
<tr role="row" class="odd">
<td>{!! $user->role->name !!}</td>
</tr>
@endforeach
I test it in Tinker it is working perfect but when I launched it in browser it throws that error.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire