lundi 27 juin 2016

Trying to get property of non-object when getting role for user

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

Tables Schema :

Users: id, role_id, name, email

Role: id, name

I test it in Tinker it is working perfect but when I launched it in browser it throws that error.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/29hGSb4
via IFTTT

Aucun commentaire:

Enregistrer un commentaire