I'm working on Laravel Access Control Level (ACL)
system. where is table contains some many to many
to relationship. User
table has many to many belongsToMany
with Role
Table and inversely many to many Role
has belongsToMany
with User
table.Again, Role
table has many to many belongsToMany
relationship with Permission
table and inversely Permission
has many to many belongsToMany
with Role
table.
I want to run a query from user table which is fetch the all permissions of a role. this role is assigned to current user through roles table.
Here is my code sample.
User Model
public function roles()
{
return $this->belongstoMany(Role::class);
}
Role Model
public function users()
{
return $this->belongsToMany(User::class);
}
public function permissions()
{
return $this->belongsToMany(Permission::class);
}
Permission Table
public function roles()
{
return $this->belongsToMany(Role::class);
}
I've tried this query using egar loading...
public function hasPermission($permission)
{
if($this->roles()->with('permissions')->get()->pluck('permissions'))
{
return true;
}
return false;
}
But it always return false
.