ellipsesynergie / api-response

Simple package to handle response properly in your API.
MIT License
377 stars 53 forks source link

ParseInclude middleware error #39

Closed spacecomx closed 7 years ago

spacecomx commented 7 years ago

Steps to reproduce

  1. Installed Lumen 5.4
  2. composer required "barryvdh/laravel-cors": "^0.9.2
  3. composer require "ellipsesynergie/api-response": "^0.14.0"
  4. Added middleware and service providers to the bootstrap/app.php file:
$app->middleware([
    'cors' => \Barryvdh\Cors\HandleCors::class,
    \EllipseSynergie\ApiResponse\Laravel\Middleware\ParseInclude::class,
]);

$app->register(Barryvdh\Cors\ServiceProvider::class);
$app->register(EllipseSynergie\ApiResponse\Laravel\LumenServiceProvider::class);
  1. Added the following to the lumen controller:

use EllipseSynergie\ApiResponse\Contracts\Response;

$posts = Post::all();
return $this->response->withCollection($posts, new PostTransformer);

Expected behaviour

Must return the post model data.

Actual behaviour

The api-response package class \EllipseSynergie\ApiResponse\Laravel\Middleware\ParseInclude::class is causing the error.

Specifically the handle methods returned response on line 41. return $next($next);

Change the return to return $next($request); then the query responds correctly.

Browser log

`Type error: Argument 1 passed to Barryvdh\Cors\CorsService::isCorsRequest() must be an instance of Symfony\Component\HttpFoundation\Request, instance of Closure given, called in /Users/waynegibson/Projects/spacecomx-ecosystem/firefly/vendor/barryvdh/laravel-cors/src/HandleCors.php on line 35`
maximebeaudoin commented 7 years ago

@spacecomx Fixed with https://github.com/ellipsesynergie/api-response/commit/78544c2fab1473fdafb2f9be344d9aacdd08e005. Tag 0.14.2 created. Thank you.