phpvms/app/Services/RoleService.php
Nabeel S 11bbcd1df7
User country mapping; ignore unused groups #443 (#584)
* Fix the user country import #443

* Ignore the old "core" groups because they're unused #443

* Properly sync roles and individual permissions #443
2020-02-24 15:12:36 -05:00

48 lines
974 B
PHP

<?php
namespace App\Services;
use App\Contracts\Service;
use App\Models\Role;
use App\Repositories\RoleRepository;
class RoleService extends Service
{
private $roleRepo;
public function __construct(RoleRepository $roleRepo)
{
$this->roleRepo = $roleRepo;
}
/**
* Update a role with the given attributes
*
* @param Role $role
* @param array $attrs
*
* @return Role
*/
public function updateRole(Role $role, array $attrs)
{
$role->update($attrs);
$role->save();
return $role;
}
/**
* @param Role $role
* @param array $permissions
*/
public function setPermissionsForRole(Role $role, array $permissions)
{
// Update the permissions, filter out null/invalid values
$perms = collect($permissions)->filter(static function ($v, $k) {
return !empty($v);
});
$role->permissions()->sync($perms);
}
}