Is it possible to add a standard parameter to all the answers in laravel? For example, what would

return response([ 'status' => 'ok' ], 200); 

Returned not only status, but also some default value (for example, a version).

 { "version": "0.1", "status": "ok" } 

    2 answers 2

    Found a solution using After Middleware:

     public function handle($request, Closure $next) { $response = $next($request); $response->header('version', '0.1'); return $response; } 
       return response($content) ->header('Version', '0.1'); 
      • explain the answer, it is not clear - michael_best
      • In this embodiment, you will have to add -> header () to all existing response (). - Xenvert
      • it is possible so if (true) {return response ($ content) -> header ('Version', '0.1');} else {return response ($ content);} - Sergey