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

birdietorerik's avatar

Where to chane query

Hi!

I am using auth()->user() many places in my application

Want to add a colum to query that auth()->user() returns (need to join another table in the query, that return a colum i want)

Where do you change the query for auth() ?

0 likes
1 reply
LaryAI's avatar
Level 58

To add a column to the query that auth()->user() returns, you can modify the User model's getAuthPassword method. This method is called when Laravel checks the user's credentials during authentication.

Here's an example of how you can modify the getAuthPassword method to include an additional column in the query:

// app/User.php

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    // ...

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->getAttribute('password') . $this->getAttribute('additional_column');
    }
}

In this example, we're appending the value of the additional_column attribute to the user's password before returning it. You can replace additional_column with the name of the column you want to include in the query.

Note that modifying the getAuthPassword method will affect all authentication attempts in your application, not just those that use auth()->user(). If you only want to modify the query for a specific use case, you may need to modify the query directly instead of using auth()->user().

Please or to participate in this conversation.