public function create(array $input)
{
if (Role::where('name', '=', $input['name'])->first()) {
throw new GeneralException('That role already exists. Please choose a different name.');
}
if (isset($input['assignees_permissions']) && count($input['assignees_permissions']) == 0) {
throw new GeneralException('You must select at least one permission for this role.');
}
$role = new Role();
$role->name = $input['name'];
$role->display_name = $input['display_name'];
$role->description = $input['description'];
if ($role->save()) {
$current = $input['assignees_permissions'];
$permissions = [];
if (count($current)) {
foreach ($current as $perm) {
if (is_numeric($perm)) {
array_push($permissions, $perm);
}
}
}
$role->attachPermissions($permissions);
return true;
}
throw new GeneralException('There was a problem creating this role. Please try again.');
}