2
votes

In Laravel, there is a php file in config called auth.php where you can change the table in which you want to do authentication with. This table in the auth.php file will be used as the default anytime you want to authenticate in laravel.

Is there a way of changing this table or model at run-time using the Auth class? Rather than using the table configured in the auth.php file, I will like to use a different table which is different from that in the auth.php file. I appreciate your help in advance.

1

1 Answers

1
votes

Presuming you are using Laravel 4 from the tag?

As you are referring to the table it would mean that you will use the DatabaseUserProvider. Unfortunately one cannot change the table that is used using the Auth facade.

However you can try to change the config setting at runtime and play with that.

// is the configuration settings for authentication
var_dump(Config::get('auth')); 

So you can change the table during runtime with something like:

Config::set('auth.table', 'myUserTable');

The same would apply if you wanted to change the model.

Config::set('auth.model', 'MyUser');