/** * Attach or detach permission on a given role. * * @param int $roleId Role Id * @param int $permissionId Permission Id * * @return void */ public function assignPermission($roleId, $permissionId) { $role = Role::findOrFail($roleId); $role->permissions()->toggle($permissionId); }
/** * Assign a role to the entity. * * @param string $role Role name * * @return mixed */ public function assignRole($role) { return $this->roles()->save(Role::where($role)->firstOrFail()); }