Skip to content

[9.x] Adds Eloquent User Provider query handler - #44226

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
DarkGhostHunter:feat/auth-query-handler
Sep 21, 2022
Merged

[9.x] Adds Eloquent User Provider query handler#44226
taylorotwell merged 3 commits into
laravel:9.xfrom
DarkGhostHunter:feat/auth-query-handler

Conversation

@DarkGhostHunter

Copy link
Copy Markdown
Contributor

What

Allows the user to register a query handler for retrieving the user from the EloquentUserProvider. This allows to tap into the query and modify columns to retrieve, like bypassing columns that may have too much data or are unused.

Auth::guard('web')->getProvider()->setQueryHandler(function ($query) {
    // ...
});

Since it works a newModelQuery() level, any change be overridden through callbacks when retrieving the user.

Auth::guard('web')->attempt([
    'email' => $email,
    'password' => $password,
    fn($query) => ...
});

Also the setQueryHandler() can be used to erase it with null and it can be retrieved for further inspection (or even wrapping).

@taylorotwell

Copy link
Copy Markdown
Member

Why did you need this in your application?

@DarkGhostHunter

DarkGhostHunter commented Sep 21, 2022

Copy link
Copy Markdown
Contributor Author

Why did you need this in your application?

I cannot alter which columns to retrieve from the table, or even use eloquent relations, without also altering all other queries in the app.

For example, I hooked a Laravel app into an existing DB where someone decided it was a good idea to have an embedded image in a column users table.

Since I cannot remove it, or move it, my only chance is to tell the User Provider to not load a column that contains 2~5 mb of data.

Another alternative is to extend the User Provider but feels so hacky...

@taylorotwell
taylorotwell merged commit a8903c9 into laravel:9.x Sep 21, 2022
@DarkGhostHunter
DarkGhostHunter deleted the feat/auth-query-handler branch September 21, 2022 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants