我如何设置如果管理员登录,那么只有他们才能在索引上看到他是管理员



我有管理中间件,它只在路由上工作

<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesAuth;
class admin
{
    /** 
* Handle an incoming request.
     * this is only for admin
     * @param  IlluminateHttpRequest  $request
     * @param  Closure  $next
     * @return mixed
     */
public function handle($request, Closure $next)
{
    if (!Auth::guest() && Auth::user()->admin) {
        return $next($request);
    }
     return redirect('/');
}
}

如何显示为
@if (Auth::user())
比用户看到名称,当管理员登录时,比管理员会看到你好管理员
我为管理员键入的内容提前感谢

假设您在用户表中有一个列角色:

@if(Auth::user()->role == 'admin')
   <span>Hello{{Auth::user()->name}}</span>
     or 
    <span>Hello admin</span>

@endif

如果您没有列角色,请将条件放入If语句中,该语句定义用户是管理员

相关内容

最新更新