I can't figure out how to how to add headers to a response from a middleware. I've used both ->header(...)
and ->headers->set(...)
but both gives errors. So how do you do it?
首先我试着
public function handle($request, Closure $next) {
$response = $next($request);
$response->headers->set('refresh', '5;url=' . route('foo'));
return $response;
}
这和Illuminate\Http\Middleware\FrameGuard.php
年时一样,但这给了
Call to a member function set() on a non-object
Second I tried with
public function handle($request, Closure $next) {
$response = $next($request);
$response->header('refresh', '5;url=' . route('foo'));
return $response;
}
但这给了
视图上不存在方法[Header].
那么,如何从中间件添加标头呢?