public function getRole(ActionInterface $action) { $role = null; foreach ($this->roleRepository->all() as $repositoryRole) { if ($repositoryRole->getName() == "Superuser") { $role = $repositoryRole; } } if ($role === null) { $role = $this->roleRepository->create(); $role->setName('Superuser'); if ($this->roleRepository->save($role) == false) { $role = null; } $role->addPermission($action, 1); } return $role; }
/** * Store a newly created role in storage. * * @return Response */ public function store() { $name = Input::get('name'); $role = $this->role_repository->create(); $user = $this->getUser(); if ($user->can('create', $role)) { $role->setName($name); $this->role_repository->save($role); $response = Redirect::route('roles.role.index'); } else { $response = Redirect::home(); } return $response; }