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
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_typestable with columnid&name(store user type names here) - Create table
userswith 4 columnsid,email/username,password&user_type_id(user_type_idis foreign key referencesidofuser_types) - Create 3 separate tables named
administrators,parentsoremployees. All 3 tables should have one columnuser_idwhich is a foreign key referencesuserstable. - Create relationship in model
- After a user login, you can determine which type of user he/she is from the
user<->user_typerelation - 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