0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Laravel6] Cache-Control レスポンスヘッダーをdefaultから変更

Posted at

確認環境 : Laravel Framework 6.20.4

Laravelでは、Cache-Controlのレスポンスヘッダーはdefalutで下記になっています。

no-cache private

no-cacheではなく、 no-store に変更したい場合、新たにmiddlewareを追加すれば変更する事ができます。

コマンド
php artisan make:middleware ChangeHeader
app/Http/Middleware/ChangeHeader.php
class ChangeHeader
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->header('Cache-Control', 'no-store, private');
        return $response;
    }
}

アプリケーションの全HTTPリクエストに適用。

app/Http/Kernel.php
    protected $middlewareGroups = [
        'web' => [
...
            \App\Http\Middleware\ChangeHeader::class, <= 追加
        ],
...
    ];
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?