Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 21, 2022
Merged

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

merged 3 commits into from
Sep 21, 2022

Conversation

DarkGhostHunter
Copy link
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
Member

Why did you need this in your application?

@DarkGhostHunter
Copy link
Contributor Author

DarkGhostHunter commented Sep 21, 2022

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