3

I want to send data between one middleware to other. As one middleware passes, I want to add some JSON response and pass to next middleware. What can be the best possible way to do it in Slim 3.

For example:

$app->post('/main_route/','reset_password')->add('middleware2')->add('middleware1');

How can I send some JSON data from middleware1 to middleware2 and then to main route?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mehul Jain
  • 113
  • 1
  • 8

1 Answers1

1

The docs explain how to do this:

In the first middleware you can do:

$request = $request->withAttribute('foo', 'bar');

In the second middleware ...

$foo = $request->getAttribute('foo');
BugHunterUK
  • 8,346
  • 16
  • 65
  • 121