public function toResponse($request)
    {
        if(! $this->handler && ! is_callable($this->handler)) {
            throw new ErrorException("No handler set");
        }

        $parameters = array_merge(
            [$request, $this->action],
            $this->parameters
        );

        try {
            $payload = call_user_func_array($this->handler, array_values($parameters));
        }
        catch (Exception $e) {
            // We'll assume that if an Exception has an error code 
            // that is explicitly defined, we want to use it as an
            // HTTP error code. if not we'll just let the 
            // Exception handler takes care of it. 
            $code = $e->getCode();

            if (! $this->isValidHttpStatusCode($code)) {
                throw $e;
            }
            
            $this->setStatusCode($code);

            return $e instanceof HasMessageBag 
                ? $this->respondWithMessageBag($e->getMessageBag(), class_basename($e))
                : $this->respondWithError($e->getMessage(), class_basename($e));
        }   
        catch (ValidationException $e) {
            throw $e;
        }

        return $this->handlePayload($payload);
    }
public function toResponse($request)
    {
        if(! $this->handler && ! is_callable($this->handler)) {
            throw new ErrorException("No handler set");
        }

        $parameters = array_merge(
            [$request, $this->action],
            $this->parameters
        );

        try {
            $payload = call_user_func_array($this->handler, array_values($parameters));
        }
        catch (Exception $e) {
            // We'll assume that if an Exception has an error code 
            // that is explicitly defined, we want to use it as an
            // HTTP error code. if not we'll just let the 
            // Exception handler takes care of it. 
            $code = $e->getCode();

            if (! $this->isValidHttpStatusCode($code)) {
                throw $e;
            }
            
            $this->setStatusCode($code);

            return $e instanceof HasMessageBag 
                ? $this->respondWithMessageBag($e->getMessageBag(), class_basename($e))
                : $this->respondWithError($e->getMessage(), class_basename($e));
        }   
        catch (ValidationException $e) {
            throw $e;
        }

        return $this->handlePayload($payload);
    }
public function toResponse ( $ request ) { if ( ! $ this -> handler && ! is_callable ( $ this -> handler ) ) { throw new ErrorException ( "No handler set" ) ; } $ parameters = array_merge ( [ $ request , $ this -> action ] , $ this -> parameters ) ; try { $ payload = call_user_func_array ( $ this -> handler , array_values ( $ parameters ) ) ; } catch ( Exception $ e ) { // We'll assume that if an Exception has an error code  // that is explicitly defined, we want to use it as an // HTTP error code. if not we'll just let the  // Exception handler takes care of it.  $ code = $ e -> getCode ( ) ; if ( ! $ this -> isValidHttpStatusCode ( $ code ) ) { throw $ e ; } $ this -> setStatusCode ( $ code ) ; return $ e instanceof HasMessageBag ? $ this -> respondWithMessageBag ( $ e -> getMessageBag ( ) , class_basename ( $ e ) ) : $ this -> respondWithError ( $ e -> getMessage ( ) , class_basename ( $ e ) ) ; } catch ( ValidationException $ e ) { throw $ e ; } return $ this -> handlePayload ( $ payload ) ; }
Call the action and return the response as
a laravel resource

@param $request
@return Resource|JsonResponse
@throws ValidationException
@throws Exception
Call the action and return the response as a laravel resource