src/Middleware/ResourceToOutput.php
public function handle($request, Closure $next)
    {
        $response = $next($request);

        if ($response instanceof ResourceResponse) {

            $format = $this->getReturnFormat($request);
            switch($format) {
                case self::RETURN_TYPE_TEXT:
                    return $this->toText($response);

                case self::RETURN_TYPE_JSON:
                default:
                    return $this->toJSON($response);
            }

        }

        return $response;
    }
public function handle($request, Closure $next)
    {
        $response = $next($request);

        if ($response instanceof ResourceResponse) {

            $format = $this->getReturnFormat($request);
            switch($format) {
                case self::RETURN_TYPE_TEXT:
                    return $this->toText($response);

                case self::RETURN_TYPE_JSON:
                default:
                    return $this->toJSON($response);
            }

        }

        return $response;
    }
Handle an incoming request.

@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed