git add .
git commit "Implement admin roles and permissions system"
This commit is contained in:
+15
-10
@@ -10,10 +10,10 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class AdminRole
|
||||
*
|
||||
*
|
||||
* @property int $admin_id
|
||||
* @property int $role_id
|
||||
*
|
||||
*
|
||||
* @property Admin $admin
|
||||
* @property Role $role
|
||||
*
|
||||
@@ -31,13 +31,18 @@ class AdminRole extends Model
|
||||
'role_id' => 'int'
|
||||
];
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->belongsTo(Admin::class);
|
||||
}
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'admin_roles');
|
||||
}
|
||||
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(Role::class);
|
||||
}
|
||||
|
||||
public function hasPermission($permission)
|
||||
{
|
||||
return $this->roles()
|
||||
->whereHas('permissions', function ($query) use ($permission) {
|
||||
$query->where('slug', $permission);
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user