Answer the question
In order to leave comments, you need to log in
How to get user->role->permissions?
There are tables.
Simple tables:
user
role
premission
Related:
user_role
premission_role
User.php
public function roles ()
{
return $this->belongsToMany(Role::class );
}
public function permissions ()
{
return $this->belongsToMany(Permission::class );
}
public function index()
{
$roles = User::find(Auth::id())->roles;
foreach ($roles as $role){
$permissions = Role::find($role->id)->permissions;
}
return view('home', compact('roles', 'permissions'));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question