/** * Create role. * * @param string $roleName * * @return \Artesaos\Defender\Role */ protected function createRole($roleName) { // No need to check is_null($role) as create() throwsException $role = $this->roleRepository->create($roleName); $this->info('Role created successfully'); return $role; }
/** * @param \Artesaos\Defender\Permission $permission * @param string $roleName */ protected function attachPermissionToRole($permission, $roleName) { // Check if role exists if ($role = $this->roleRepository->findByName($roleName)) { $role->attachPermission($permission); $this->info('Permission attached successfully to role'); } else { $this->error('Not possible to attach permission. Role not found'); } }
/** * Create a new role. * Uses a repository to actually create the role. * * @param string $roleName * * @return \Artesaos\Defender\Role */ public function createRole($roleName) { return $this->roleRepository->create($roleName); }
/** * Create a new role. * Uses a repository to actually create the role. * * @param string $roleName * @param string $readableName * @param string $type * * @return \Artesaos\Defender\Role */ public function createRole($roleName, $readableName = null, $type = 'business') { return $this->roleRepository->create($roleName, $readableName, $type); }
public function it_should_throw_an_exception_when_the_given_role_already_exists(RoleRepository $roleRepository) { $roleRepository->create('foo')->shouldBeCalled()->willThrow(new \Exception()); $this->shouldThrow('\\Exception')->duringCreateRole('foo'); }
/** * Create a new role * * @param Request $request * @return array */ public function store(Request $request) { $name = $request->get('name'); $newRole = $this->rolesRepository->create($name); return response()->json($newRole, 201); }
/** * Get a role by id * * @param $id role_id * @return \Illuminate\Http\JsonResponse */ public function show($id) { $role = $this->roleRepository->findById($id); return response()->json($role, 200); }