Laravel
LaravelでTrying to get property 'headers' of non-objectと出た時の解決方法
いつもご利用ありがとうございます。
この記事には広告が掲載されており、その広告費によって運営しています。
オススメ本
Laravel の Middleware でミスると、
LaravelでTrying to get property 'headers' of non-object
と、エラーが発生します。
その対処法について書いています。
結論
return $next($request);の記述がない
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null ...$guards
* @return mixed
*/
// public function handle(Request $request, Closure $next, ...$guards)
public function handle()
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
// return $next($request);
}