Laravel Auth :: check()
问题描述:
我正在开发一个laravel.I有一个表名用户类型。我有两种类型的用户'common'和'admin',我分别设置id和2。我为不同的用户提供了两种类型的导航栏。常用的是所有用户,管理员用于注册用户。但是,每次我必须手动将user_type_id设置为2时,才会向注册用户授予管理员导航去我的数据库。但我想动态地这样做,如果(Auth :: check()){user_type_id = 2}。我该怎么做?Laravel Auth :: check()
这是我标题代码,如果你需要看到:
<p style="display:none;">
@if(Auth::check())
{{ $a = 'includes.navs.'.Auth::user()->userType->name }}
@else
{{ $a = "includes.navs.common" }}
@endif
</p>
答
如果我理解正确:
- 普通用户存储与1
- 一个
user_type_id
存储管理员用户与user_type_id
of 2
鉴于你可以只是这样做:
<p style="display:none;">
@if(Auth::check())
@if(Auth::user()->user_type_id == 2)
{{ $a = 'includes.navs.'.Auth::user()->userType->name }}
@endif
@else
{{ $a = "includes.navs.common" }}
@endif
</p>
谢谢你。我感谢你的帮助 –