From d9a25bf1fd42ced3610b6bdd3d7ddee8f2672cca Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Thu, 17 Sep 2015 16:59:34 +0200 Subject: [PATCH] Add getAuthIdentifierName to Authenticable trait --- Authenticatable.php | 10 ++++++++++ EloquentUserProvider.php | 2 +- GenericUser.php | 14 +++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Authenticatable.php b/Authenticatable.php index 46101d2aa..ae55d8fec 100644 --- a/Authenticatable.php +++ b/Authenticatable.php @@ -4,6 +4,16 @@ trait Authenticatable { + /** + * Get the name of the unique identifier for the user. + * + * @return string + */ + public function getAuthIdentifierName() + { + return $this->getKeyName(); + } + /** * Get the unique identifier for the user. * diff --git a/EloquentUserProvider.php b/EloquentUserProvider.php index e2b6dc7df..0df8c50c8 100755 --- a/EloquentUserProvider.php +++ b/EloquentUserProvider.php @@ -59,7 +59,7 @@ public function retrieveByToken($identifier, $token) $model = $this->createModel(); return $model->newQuery() - ->where($model->getKeyName(), $identifier) + ->where($model->getAuthIdentifierName(), $identifier) ->where($model->getRememberTokenName(), $token) ->first(); } diff --git a/GenericUser.php b/GenericUser.php index d349d4983..b6880c0ca 100755 --- a/GenericUser.php +++ b/GenericUser.php @@ -24,6 +24,16 @@ public function __construct(array $attributes) $this->attributes = $attributes; } + /** + * Get the name of the unique identifier for the user. + * + * @return string + */ + public function getAuthIdentifierName() + { + return 'id'; + } + /** * Get the unique identifier for the user. * @@ -31,7 +41,9 @@ public function __construct(array $attributes) */ public function getAuthIdentifier() { - return $this->attributes['id']; + $name = $this->getAuthIdentifierName(); + + return $this->attributes[$name]; } /**