Support the ongoing development of Laravel.io →
posted 9 years ago
Requests
Last updated 2 years ago.
0

I think you should use:

$response = $next($request);

$response->header->set('Cache-Control' , 'public');
$response->header->set('Last-Modified', new DateTime("now"));
$response->header->set('Expires', new DateTime("tomorrow"));

return $response;
0

tlorentzen said:

Im trying to remove the Cache-Control: no-cache from my Laravel 5, so i created a middleware to handle this.

if(!$request->is('admin/*')) { $response = $next($request);

   return $response->header('Cache-Control' , 'public')

->header('Last-Modified', new DateTime("now")) ->header('Expires', new DateTime("tomorrow")); }

Sometime the response object is instance of RedirectResponse, and for some reason that does not include a method header, but looking in the Laravel Api it should have the header method. http://laravel.com/api/5.0/Illuminate/Http/RedirectResponse.html

Does the Laravel RedirectResponse not extend the Symfony RedirectResponse? And why does the $next() return the Symfony RedirectResponse and not the Laravel RedirectResponse?

Error: Call to undefined method Symfony\Component\HttpFoundation\RedirectResponse::header()

Anyone know what to do about this?

I have the exact same problem. Did you find a solution?

0

Try

$response->header->set('Cache-Control' , 'public')

0

In my case:

$response->headers->set('Access ....

solved problem

0

Sign in to participate in this thread!

Eventy

Your banner here too?

tlorentzen tlorentzen Joined 17 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.