0

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

Dhiraj Patel
  • 269
  • 1
  • 13

1 Answers1

1

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',
],
Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63