Conditions | 3 |
Paths | 3 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | public function handle($request, Closure $next) |
||
19 | { |
||
20 | // First, set the header so any other middleware knows we're |
||
21 | // dealing with a should-be JSON response. |
||
22 | $request->headers->set('Accept', 'application/json'); |
||
23 | |||
24 | // Get the response |
||
25 | $response = $next($request); |
||
26 | |||
27 | if (!empty($response->exception)) { |
||
28 | return response() |
||
29 | ->exceptionError($response->exception, '', $response->status(), $response->headers->all()); |
||
30 | } |
||
31 | |||
32 | // If the response is not strictly a JsonResponse, we make it |
||
33 | if (!$response instanceof JsonResponse) { |
||
34 | return response() |
||
35 | ->success($response->content(), '', $response->status(), $response->headers->all()); |
||
36 | } |
||
37 | |||
38 | return $response; |
||
39 | } |
||
40 | } |
||
41 |