Laravel自定义身份验证 [英] Laravel Custom Auth

查看:131
本文介绍了Laravel自定义身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里进行登录验证

$LoginData   = Input::except(array('_token')) ;
if(Auth::attempt($LoginData)) 
{
    return 'success';
}

我的表是不同的,所以在这里我在auth.php

My Table is different so, here i change the table name in auth.php

'table' => 'administrators'

但是我可以从下拉菜单中选择用户类型.

But I have the dropdown to choose for the usertype.

那么我该如何根据usertypeinput选择用于身份验证的表.

So how can i choose the tables for Authentication according to the usertypeinput.

即表可能是管理员,父母或雇员

i.e., Table may be administrators or parents or employees

推荐答案

我不知道Laravel是否支持动态更改身份验证表名称.我可以建议您一个快速的解决方案.

I don't know whether Laravel supports the change of auth table name on fly or not. I can suggest you a quick solution.

根据数据库设计的一般化理论,应将相同类型的信息存储到一个实体集.并且根据专业化理论,如果实体集可以为每个实体提供各种类型的信息,则将它们分解为子实体集.

According to generalization theory of database design, you should store same type of information to one entity set. And according to specialization theory, if entity set can have various types of information for each entity, break them down into sub entity sets.

建议:

  • 使用id列创建user_types表& name(在此处存储用户类型名称)
  • 创建具有4列idemail/usernamepassword和&列的表users user_type_id(user_type_iduser_types的外键引用id)
  • 创建3个单独的表,分别命名为administratorsparentsemployees.所有3个表都应有一个列user_id,这是一个外键引用users表.
  • 在模型中创建关系
  • 用户登录后,您可以根据user<->user_type关系确定他/她是哪种用户
  • 您现在可以从登录页面视图中删除用户类型下拉列表(您已经向整个星球公开了有关应用程序的一些重要信息(3种用户类型),对您的应用程序有害吗?)
  • Create user_types table with column id & name (store user type names here)
  • Create table users with 4 columns id, email/username, password & user_type_id (user_type_id is foreign key references id of user_types)
  • Create 3 separate tables named administrators, parents or employees. All 3 tables should have one column user_id which is a foreign key references users table.
  • Create relationship in model
  • After a user login, you can determine which type of user he/she is from the user<->user_type relation
  • You can get rid of the usertype dropdown from login page view now (You were disclosing some important information (3 user types) about your application to the whole planet, isn't it harmful for your application?)

有关泛化和更多信息的更多信息专业化: 泛化,专业化和聚合

这篇关于Laravel自定义身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆