app/Api/V1/Controllers/RoleController.php
/**
     * Store a newly created role in storage.
     *
     * @param RoleRequest $request
     * @return Response
     * @throws \Illuminate\Validation\ValidationException
     */
Store a newly created role in storage.
@param RoleRequest $request
@return Response
@throws \Illuminate\Validation\ValidationException
Store a newly created role in storage . @param RoleRequest $request @return Response @throws \ Illuminate \ Validation \ ValidationException
public function store(RoleRequest $request)
    {
        $this->validate($request, ['name' => 'required|unique:roles']);
        if ($role = Role::query()->create($request->only('name'))) {
            $permissions = $request->get('permissions', []);
            if (!Permission::areValidPermissions($permissions)) {
                return $this->withMessage('We don\'t recognize some of the permissions you set', 400);
            }
            if ($role->syncPermissions($permissions)) {
                return $this->withMessage('Role created successfully');
            }
            throw new StoreResourceFailedException('Role was created, no permission was assigned');
        }
        throw new StoreResourceFailedException('Role couldn\'t be stored');
    }
public function store ( RoleRequest $ request ) { $ this -> validate ( $ request , [ 'name' => 'required|unique:roles' ] ) ; if ( $ role = Role :: query ( ) -> create ( $ request -> only ( 'name' ) ) ) { $ permissions = $ request -> get ( 'permissions' , [ ] ) ; if ( ! Permission :: areValidPermissions ( $ permissions ) ) { return $ this -> withMessage ( 'We don\'t recognize some of the permissions you set' , 400 ) ; } if ( $ role -> syncPermissions ( $ permissions ) ) { return $ this -> withMessage ( 'Role created successfully' ) ; } throw new StoreResourceFailedException ( 'Role was created, no permission was assigned' ) ; } throw new StoreResourceFailedException ( 'Role couldn\'t be stored' ) ; }
Store a newly created role in storage.
Store a newly created role in storage .
//verify permissions to make sure selected permissions are in db