调用RevalidateBackHistory.php中未定义的方法Symfony\Component\HttpFoundation\BinaryFileResponse::header()
我已经编写了一个中间件,这样用户在登录后就不能再次进入登录页面。如果已经登录,将重定向到管理面板 代码如下: 我在一个名为NoticeControl的控制器中调用了它调用RevalidateBackHistory.php中未定义的方法Symfony\Component\HttpFoundation\BinaryFileResponse::header(),php,laravel-5.4,Php,Laravel 5.4,我已经编写了一个中间件,这样用户在登录后就不能再次进入登录页面。如果已经登录,将重定向到管理面板 代码如下: 我在一个名为NoticeControl的控制器中调用了它 public function __construct() { $this->middleware('auth'); $this->middleware('revalidate'); //this is the middleware }
public function __construct()
{
$this->middleware('auth');
$this->middleware('revalidate'); //this is the middleware
}
我还在这个控制器中定义了一个函数来下载一个文件,代码是
public function downloadFile($id)
{
$notice = new Notice();
$data = $notice->where('id',$id)->first();
if (file_exists(public_path().'/uploads/files/'.$data->file))
{
return response()->download(public_path().'/uploads/files/'.$data->file);
}
else
{
Session()->flash('message.notice',"File not found");
return redirect('admin/notice/info');
}
}
下载功能是完美的,我在另一个控制器中也使用了这个功能。但是当我调用downloadFile()函数时,问题发生在这个控制器内部,它给出了以下异常
(1/1)fatalthrowable错误
调用未定义的方法Symfony\Component\HttpFoundation\BinaryFileResponse::header()
在RevalidateBackHistory.php中(第20行)
在Pipeline.php中的RevalidateBackHistory->handle(对象(请求)、对象(关闭))(第148行)
如果我从构造函数中删除重新验证中间件,该函数工作正常。这个问题的解决办法是什么 您应该使用以下代码编辑
句柄
函数
$response = $next($request);
$headers = [
'Cache-Control' => 'nocache, no-store, max-age=0, must-revalidate',
'Pragma','no-cache',
'Expires','Fri, 01 Jan 1990 00:00:00 GMT',
];
foreach($headers as $key => $value) {
$response->headers->set($key, $value);
}
return $response;
用于设置RevalidateBackHistory中间件文件中的标题返回在哪里?
return$response代码>在末尾
$response = $next($request);
$headers = [
'Cache-Control' => 'nocache, no-store, max-age=0, must-revalidate',
'Pragma','no-cache',
'Expires','Fri, 01 Jan 1990 00:00:00 GMT',
];
foreach($headers as $key => $value) {
$response->headers->set($key, $value);
}
return $response;