我正在使用 Laravel 7.4 版本
我需要将 Header 添加到所有视图中。
我在路径 App\Providers\ViewServiceProvider 中创建了一个 ViewServiceProvider 并添加到 config/app.php
这是我在启动功能中的代码
public function boot()
{
App::before(function($request)
{
Response::header('Cache-Control', 'nocache, no-store, max-age=0, s-maxage=0,must-revalidate');
Response::header('Pragma', 'no-cache');
Response::header('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT');
});
}
我收到这个错误
应用::之前未找到
添加标题的替代方法是什么
我也试过中间件
public function handle(Request $request, Closure $next)
{
$response = $next($request);
$response->header('Cache-Control', 'nocache, no-store, max-age=0, s-maxage=0,must-revalidate');
$response->header('Pragma', 'no-cache');
$response->header('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT');
return $response;
}
这也没有添加到 html 标题中。