Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

m-naderian's avatar

Reviewing PHP code in Laravel framework

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.

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

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.

1 like

Please or to participate in this conversation.