Can you show your login code?
Authentication return "Column 'id' in where clause is ambiguous" because a GlobalScope
Hi,
I'm having a trouble with authentication, when I make a login, Laravel returns the error: "Column 'id' in where clause is ambiguous" because I have a GlobalScope with JOIN:
Column 'id' in where clause is ambiguous (SQL: select * from `users` inner join `playables` as `p` on `users`.`id` = `p`.`user_id` inner join `league_of_legends` as `lol` on `p`.`playable_id` = `lol`.`id` and `p`.`playable_type` like '%LeagueOfLegends%' where `id` = 1 and `users`.`deleted_at` is null and `users`.`banned` = 0 limit 1)
I tried to rename the primary key of model User but this cased others errors. There is an alternative? Or I have to use Local Scopes??
Thanks.
Good News!!
-
I was wrong. Which is good.
-
It's easy. (pretty easy).
Bottom line, you create your own CustomUserProvider.
Here are the steps:
- Create MyCustomUserProvider {} class in App\ (or wherever)
Note: It must implement Illuminate\Contracts\Auth\UserProvider;
I think this is the 'hard-ish' part.
See: Illuminate\Auth\DatabaseUserProvider and Illuminate\Auth\EloquentUserProvider; I think the DatabaseUserProvider is easier to figure out, and perhaps more closely matches what you need to do.
- Create MyCustomAuthProvider class in app/Providers (or YourCustomAuthProvider)
This is where you set $app->['auth'] to the above MyCustomUser provider
public function boot()
{
$this->app['auth']->extend('my-custom',function()
{
return new MyCustomUserProvider(new User); //see here. a (blank) User gets past in to constructor.
});
}
- Register MyCustomUserProvider in config/app.php (otherwise it's not found)
'providers' => [
'App\Providers\MyCustomAuthProvider',
...
]
- Update config/auth.php
change this:
'providers' => [
'users' => [
'driver' => 'eloquent', //nope dont want this one!
'model' => App\User::class,
],
//...
]
to this in order to use 'MyCustomeUserProvider
'providers' => [
'users' => [
'driver' => 'my-custom', //see how this matches the above $this->app['auth']->extend('my-custom', ...
'model' => App\User::class,
],
//...
]
Final Note: I cobbled this together from different sources.
https://laravel.io/forum/11-04-2014-laravel-5-how-do-i-create-a-custom-auth-in-laravel-5 <-- most steps. https://laracasts.com/discuss/channels/laravel/replacing-the-laravel-authentication-with-a-custom-authentication <-- helps on implementation of Illuminate\Auth\UserProvider;
check them out for details.
Please or to participate in this conversation.