Laravel 5:如果已登录用户,请更改导航栏 [英] Laravel 5: Change navbar if user is logged
本文介绍了Laravel 5:如果已登录用户,请更改导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Laravel,MVC和模板引擎的新手.
I'm completely new to Laravel, MVC and templating engines in general.
如果用户已登录,我需要显示某些导航栏按钮和选项,例如:通知,注销,个人资料等...,否则显示登录按钮.
I need to show certain navbar buttons and options if a user is logged in such as: Notifications, Logout, Profile, etc... and a Login button otherwise.
对于我如何以正确的方式解决此问题的任何帮助,我们深表感谢. 这是我目前正在考虑的内容:
Any help on how I could address this the right way is greatly appreciated. This is what I'm considering at the moment:
-
User
对象总是传递给视图. - 该视图检查是否已设置
User
(表示已登录)以包括用于导航栏的适当的部分刀片模板.
- A
User
object is always passed to the view. - The view checks if the
User
is set (meaning it's logged in) to include the appropriate partial blade template for the navbar.
app.blade.php:
app.blade.php:
...
@if (isset($user))
@include('partials.navbarlogged')
@else
@include('partials.navbar')
...
这是最好的方法吗? 感谢您的宝贵时间!
Is this the best method? Thanks for your time!
推荐答案
如果您使用的是Laravel 5内置的用户模型,则只需执行
If you are using Laravel 5's built in User model you can simply do
@if (Auth::check())
//show logged in navbar
@else
//show logged out navbar
@endif
这篇关于Laravel 5:如果已登录用户,请更改导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文