Laravel自定义身份验证

编程入门 行业动态 更新时间:2024-10-24 08:31:59
本文介绍了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列id,email/username,password和&列的表users user_type_id(user_type_id是user_types的外键引用id)
  • 创建3个单独的表,分别命名为administrators,parents或employees.所有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自定义身份验证

本文发布于:2023-11-04 00:52:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   身份验证   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!