简体   繁体   English

用户身份验证,如果管理员或用户laravel 5.8

[英]User Authentication if Admin or User laravel 5.8

I am currently new to Laravel. 我现在是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? 通过运行php artisan make:auth命令很容易但是我试图确定登录的用户是普通用户还是管理员?

$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. 我试图将其添加到我的user模型以确定用户是否是管理员,并尝试通过添加此代码来修改我的LoginController

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 我认为没有必要检查$user == 1它只返回tru或false所以你可以直接检查

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

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

return "not admin";

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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