中间件代码
$request->attributes->add(['username'=>$username]); $requset->merge(['username'=>$username]); return $next($request)
控制器代码
return view('index',['username'=>request()->get('username')]);
view视图
{{$username}}