I want to set headers as array(\'Cache-Control\'=>\'no-cache, no-store, max-age=0, must-revalidate\',\'Pragma\'=>\'no-cache\',\'Expires\'=>\'Fri, 01 Jan 1990
For future readers using Laravel 5.x, this can be handled out of the box without needing to create any custom middleware.
Laravel has the response() helper method, which you can chain headers to very easily.
use Response;
// Or possibly: use Illuminate\Http\Response; depending on your aliases used.
// Add a series of headers
return response($content)
->header('Content-Type', 'text/xml')
->header('X-Header-One', 'Header Value');
// Or use withHeaders to pass array of headers to be added
return response($content)
->withHeaders([
'Content-Type' => 'text/xml',
'X-Header-One' => 'Header Value'
]);
Read more about it in the documentation, because it can handle attaching a number of things; cookies, views, and more.