Dhiraj Patel
Dhiraj Patel

Reputation: 267

how to set header details in laravel 5.0 for all views?

i want to assign following code to all views in laravel 5.0. this code is in php but i want similar like this in laravel 5.0

  //set headers to NOT cache a page
  header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
  header("Pragma: no-cache"); //HTTP 1.0
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

i could not find solution for cache issue when user clicks on browser back button.

your help would be appreciable

thanks

Upvotes: 0

Views: 1087

Answers (1)

Sulthan Allaudeen
Sulthan Allaudeen

Reputation: 11310

In your routes.php have the below code in the top

App::after(function($request, $response)
{
    $response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
    $response->headers->set('Pragma','no-cache');
    $response->headers->set('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
});

As you got Call to undefined method Illuminate\Foundation\Application error, It means you need to install illuminate to your laravel 5.0

Here are the steps :

Step 1 :

From your composer composer require "illuminate/html":"5.0.*"

Step 2 :

In your app.php add the following lines

'providers' => [
    ...

    'Illuminate\Html\HtmlServiceProvider',
],

'aliases' => [

    ...

    'Form'=> 'Illuminate\Html\FormFacade', 
    'HTML'=> 'Illuminate\Html\HtmlFacade',
],

Upvotes: 1

Related Questions