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 Laravel >= 5.2 yet, following @Amarnasan answer , although I used mine for API calls
In Laravel 5, using Middleware, creating a new file, modifying an existing file:
New file: app/Http/Middleware/AddHeaders.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Routing\Redirector;
use Illuminate\Http\Request;
use Illuminate\Foundation\Applicaion;
class AddHeaders
{
public function handle($request, Closure $next)
{
$response = $next($request);
$response->header('Cache-Control', 'max-age=36000, public');
//$response->header('another header', 'another value');
return $response;
}
}
Modify existing file app/Kernel.php so that you can use with each specific route
protected $routeMiddleware = [
.
.
.
'myHeader' => \App\Http\Middleware\AddHeaders::class,
];
And you're set.
Then you can use it like so for individual routes or groups
$api->get('cars/all', 'MyController@index')->middleware(['myHeader']);;