gpt4 book ai didi

php - 没有缓存头的 Laravel 重定向

转载 作者:可可西里 更新时间:2023-11-01 16:56:34 24 4
gpt4 key购买 nike

我正在使用 Laravel 3,除了通过 Response::make() 之外,如何以任何方式设置 header 并不明显。

我正在做这样的重定向:

return Redirect::to('admin/check');

我想为重定向设置一个额外的 no-cache header ,如下所示:

"Cache-Control: no-store, no-cache, must-revalidate"

我意识到我可以直接在 PHP 中执行此操作,但是有什么方法可以通过 Laravel 设置响应 header 吗?

最佳答案

当您调用 Redirect::to() 时,Laravel 会实例化一个具有 302 状态和 Location header 的 Response 对象。该 Response 对象然后由 Controller 返回并呈现为正确的 HTTP 响应,因此,在 Controller 时间,您仍然可以更改其 header 。

更准确地说,class Redirect extends Response。看看here您只需使用:

return Redirect::to('admin/check')
->header('Cache-Control', 'no-store, no-cache, must-revalidate');

关于php - 没有缓存头的 Laravel 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15371943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com