Where can I set headers in laravel

前端 未结 7 860
别那么骄傲
别那么骄傲 2020-11-29 20:08

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

7条回答
  •  醉话见心
    2020-11-29 20:54

    Working on Laravel 4.2. I'm using filter for this, so in filters.php i have:

    Route::filter('no-cache',function($route, $request, $response){
    
        $response->header("Cache-Control","no-cache,no-store, must-revalidate");
        $response->header("Pragma", "no-cache"); //HTTP 1.0
        $response->header("Expires"," Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    
    });
    

    Than I attach this filter to routes or controllers. Controller attached looks like this for me:

    public function __construct() {
    
            $this->beforeFilter('onestep',array('except' => 'getLogin'));
            $this->beforeFilter('csrf',array('on' => 'post'));
            $this->afterFilter("no-cache", ["only"=>"getIndex"]);
        }
    

    This filter is attached as afterFilter.

提交回复
热议问题