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

EloquentUserProvider RetrieveById & RetrieveByToken - Ambiguous ID #43274

Closed
BenWalters opened this issue Jul 19, 2022 · 1 comment
Closed

EloquentUserProvider RetrieveById & RetrieveByToken - Ambiguous ID #43274

BenWalters opened this issue Jul 19, 2022 · 1 comment

Comments

@BenWalters
Copy link
Contributor

BenWalters commented Jul 19, 2022

  • Laravel Version: 9.11.0
  • PHP Version: 8.1.8
  • Database Driver & Version: MySQL - 8.0.26

Description:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous
Caused by Illuminate\Auth\EloquentUserProvider:52 (retrieveById)

When applying a global scope to our Users model that also has an ID field, the above mentioned function is not qualifying the field name (adding the table prefix), thus causing the "'id' in where clause is ambiguous" error.

Seemingly the same issue was raised here - laravel/ideas#1956
I believe that wrapping $model->getAuthIdentifierName() in $model->qualifyColumn() would resolve the issue and should be implemented in both the retrieveById and retrieveByToken functions of EloquentUserProvider.

BenWalters added a commit to BenWalters/framework that referenced this issue Jul 19, 2022
@driesvints
Copy link
Member

Let's see how your PR goes 👍

BenWalters added a commit to BenWalters/framework that referenced this issue Jul 19, 2022
taylorotwell pushed a commit that referenced this issue Jul 19, 2022
* [8.x] Protect against ambiguous columns

Resolving #43274

* Updating tests.
taylorotwell pushed a commit to illuminate/auth that referenced this issue Jul 19, 2022
* [8.x] Protect against ambiguous columns

Resolving laravel/framework#43274

* Updating tests.
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

No branches or pull requests

2 participants