Laravel Custom Auth

感情迁移 提交于 2019-12-07 19:46:07

问题


Here i do the Login Validation

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

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.

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

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


回答1:


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.

Suggestion:

  • 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?)

More info about generalization & specialization: Generalization, Specialization and Aggregation



来源:https://stackoverflow.com/questions/27656636/laravel-custom-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!