1public function handle($request, Closure $next)
2{
3 // get response
4 $response = $next($request);
5
6 // if response is JSON
7 if($response instanceof JsonResponse){
8
9 $current_data = $response->getData();
10
11 $current_data->userData = ['attach some additional user data'];
12
13 $response->setData($current_data);
14
15 }
16
17 return $response;
18}
1this middleware would perform its task after the request is handled by the application:
2
3<?php
4
5namespace App\Http\Middleware;
6
7use Closure;
8
9class AfterMiddleware
10{
11 public function handle($request, Closure $next)
12 {
13 $response = $next($request);
14
15 // Perform action
16
17 return $response;
18 }
19}