Have a look here https://github.com/laravel/framework/blob/7.x/src/Illuminate/Auth/GenericUser.php#L32
and
here https://laravel.com/api/7.x/search.html?search=getAuthIdentifier
The api points to where the code is.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm somehow a newcomer to Laravel and professional PHP development. I started reviewing Laravel framework code and started with Auth package.
I saw a code in Authenticatable.php like the one bellow:
public function getAuthIdentifier()
{
return $this->{$this->getAuthIdentifierName()};
}
why the code is written this way? what does that mean?
Thanks in advance.
It uses a function to return the name of the column to be used, and then returns its value.
so if the function getAuthIdentifierName() returns the string 'username' then the function you have highlighted is the same as writing
public function getAuthIdentifier()
{
return $this->username;
}
Its done this way because it is using a trait to include code in your app\Http\Controllers\Auth\LoginController.
If you wanted to use a different database column for the user identifier then you can create a function in your login controller like;
public function getAuthIdentifierName()
{
return 'email';
}
This method will override the one in the trait and then getAuthIdentifier will return the contents of the email column not the username column
You would not normally use this level of abstraction in your code, its used here to make the framework extensible.
Please or to participate in this conversation.