LARAVEL-登录时显示用户名 [英] LARAVEL - show name of the user when logged in
本文介绍了LARAVEL-登录时显示用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个登录页面"admin-login",该页面在通过身份验证后会重定向到页面"admin".我想在管理员"页面上显示登录用户的名称.
I have made a login page 'admin-login' which redirected to a page 'admin' when authenticated. I want to display the name of the logged in user on the 'admin' page.
看看我的代码: 控制器:
Have a look at my code: Controller:
public function login(Request $req) {
$email = $req->input('email');
$password = $req->input('password');
$checkLogin = DB::table('admin')->where(['email'=>$email,'password'=>$password])->get();
if(count($checkLogin) > 0) {
return view('admin')->with(['name'=>" "]);
}
else {
// echo "Login Failed!";
return Redirect::route('admin-login')->with(['error'=> "Invalid email or Password!!"]);
}
}
我不知道在这里写什么'with(['name'=>"]);'.请帮我.
I don't know what to write here 'with(['name'=>" "]);'. Plz help me out.
查看:
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
@guest
<li><a href="{{ route('login') }}">Login</a></li>
<li><a href="{{ route('register') }}">Register</a></li>
@else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true">
{{ Session::get('name') }} <span class="caret"></span>
</a>
</li>
</ul>
推荐答案
您可以通过Auth::user()
他的名字叫
Auth::user()->name
;
这篇关于LARAVEL-登录时显示用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文