简体   繁体   中英

User Authentication if Admin or User laravel 5.8

I am currently new to Laravel. This is my fist time building with this framework. I 'm trying to create a login. It was easy by running the php artisan make:auth command however i'm trying to determine if the user that was login is regular user or admin?

$table->boolean('is_admin')->nullable();

I've tried to add that to my user model to determine if user is admin or not and try to modify my LoginController by adding this code.

public function determineTypeLogin(Request $request)
{
    $user = auth()->user()->is_admin;

    if ($user == 1) {
        return "admin";
    }

    return "not admin";
}

however no luck.. Please help

Please check this

public function determineTypeLogin(Request $request)
{
    $user = Auth::user()->is_admin;

    if ($user == 1) {
        return "admin";
    }

    return "not admin";
}

I think no need to check $user == 1 it return only tru or false so you can dirctly check like

public function determineTypeLogin(Request $request) { $user = Auth::user()->is_admin;

if ($user) {
    return "admin";
}

return "not admin";

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM