Skip to content

Commit

Permalink
Add getAuthIdentifierName to Authenticable trait
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrouwers committed Sep 17, 2015
1 parent a18938f commit d9a25bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Authenticatable.php
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion EloquentUserProvider.php
Expand Up @@ -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();
}
Expand Down
14 changes: 13 additions & 1 deletion GenericUser.php
Expand Up @@ -24,14 +24,26 @@ 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.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->attributes['id'];
$name = $this->getAuthIdentifierName();

return $this->attributes[$name];
}

/**
Expand Down

0 comments on commit d9a25bf

Please sign in to comment.