You can also handle this directly in the controller used for the authentication.
Jul 6, 2023
6
Level 8
Getting the Authentication username column
I need to get the auth username that is used by the app for authentication from a User object. The column used for authentication is changing based on system/environment (can be email or username or some other column)
Is it a good idea to put that as a public property in the User model (I will add username_column to auth.php):
class User extends Authenticatable
{
public $username_column = config('auth.username_column')
}
or as a getter in the User model:
class User extends Authenticatable
{
public function getUsernameColumn()
{
return config('auth.username_column');
}
}
Or something else?
Level 80
@Ligonsker Yes. And you can override the value in your User class to return whatever the actual value is:
class User extends Authenticatable
{
public function getAuthIdentifierName()
{
return config('auth.username_column');
}
}
2 likes
Please or to participate in this conversation.