I use Sentinel Framework to made authorization and authentication. But I stuck in User Management.
I want to show details like Email - Role but I still stuck here.
My Database:
role: ID, slug, name
user: ID, Email, ...
role_users: user_id, role_id
My Controller
public function getAll(){
$user = User::all();
return view('admin.user.list',['user'=>$user]);
}
My UserModel
public function Role(){
return $this->belongsToMany('App\Role','role_users','user_id', 'role_id');
}
Then my view
<?php foreach ($user as $u): ?>
<tr>
<td>{{$u->Role->name}}</td>
</tr>
<?php endforeach; ?>
Then I got an error
Property [slug] does not exist on this collection instance.
If I write
<td>{{$u->Role}}</td>
It's appears an array like
[{"id":1,"slug":"admin","name":"admin","permissions":null,"created_at":null,"updated_at":null,"pivot":{"user_id":1,"role_id":1}}]
But I can't access to the "slug" property :(
How can I do that ?
Thanks a lot !!!