Laravel 5.3依赖用户进行身份验证

I have an table hosts and want to redirect to a different page when the user is admin (DB is_admin boolean). I use the following Authentication method:

public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->check())
    {
        if(Auth::user()->isAdmin == 1) {
            return redirect('/home');
        }
        else
        {
            return redirect('/api');
        }
    }

    return $next($request);
}

My hosts class:

public function isAdmin()
{
    return $this->is_admin;
}

}

Can anyone help me?

Try doing like this --

Middleware

if ( Auth::check() && Auth::user()->isAdmin() ) {
    return $next($request);
}

return redirect('/');

It is because boolean return 1 or 0 which means true or false. So no need to check it wheather it is true by == true

Dont forget to add a column in the database with is_admin because you are telling to get is_admin from the database

Change

if(Auth::user()->isAdmin == 1) {

to

if(Auth::user()->isAdmin() == 1) {

You defined a function, not a property