2

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 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I shall make it use. But i also need to know whether i want to change the auth table name on the fly
I will let you know if I can find any way. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.