简体   繁体   English

Laravel 4中的管理员和非管理员身份验证

[英]Admin and non-admin authentication in Laravel 4

I want to have an authentication for Admin and for Non-admin. 我想对管理员和非管理员进行身份验证。 I'm having the admin infromation in 'users' db table, and non-admin information in 'customers' table. 我在“用户”数据库表中有管理员信息,在“客户”表中有非管理员信息。 How to use Laravel's Auth class to create authentication for this two different user roles? 如何使用Laravel的Auth类为这两个不同的用户角色创建身份验证?

for starter you should merge the two tables and then define a new column named "role_id" and then a new table called "roles" then as you attempt like this: 首先,您应该合并两个表,然后定义一个名为“ role_id”的新列,然后定义一个名为“ roles”的新表,然后像这样尝试:

if (Auth::attempt(array('email' => $email, 'password' => $password)))
    {
        Session::put('role',  Auth::user()->role_id);
        return Redirect::intended('dashboard');
    }

then via Session you can get the role whenever it's needed and decide to whatever yo want to do with it... note: also edit your User model so role_id can be accessible happy coding 然后通过会话,您可以在需要时获取该角色,然后决定自己想使用的角色...注意:还可以编辑您的用户模型,以便可以访问role_id进行愉快的编码

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

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