mardi 1 mars 2016

Laravel overriding EloquentUserProvider to change password field name in validateCredentials()

I've managed to change the password field in the code through overriding various classes/methods. But I after trying to override EloquentUserProvider and it's validateCredentials() method I keep getting an error -

ErrorException in AuthUserProvider.php line 11:
Argument 1 passed to App\Providers\AuthUserProvider::__construct() must be an instance of Illuminate\Contracts\Hashing\Hasher, instance of Illuminate\Foundation\Application given, called in /Users/Sagun/Sites/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146 and defined

I created an override App\Providers\AuthUserProvider.php - namespace App\Providers;

use Illuminate\Contracts\Auth\Authenticatable as UserContract;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Auth\EloquentUserProvider;

class AuthUserProvider extends EloquentUserProvider {


public function __construct(HasherContract $hasher, $model)
{
    parent::__construct($hasher, $model);
}

/**
 * Validate a user against the given credentials.
 *
 * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
 * @param  array  $credentials
 * @return bool
 */
public function validateCredentials(UserContract $user, array $credentials)
{
    return true;
}

}

I'm guessing app\Providers isn't the namespace is requires but I also tried Illuminate\Auth as the namespace however that wouldn't work as well, as even after the declaration in app.config it failed to find the class. Or this file may need to be placed in a new directory?



via Chebli Mohamed

1 commentaire:

  1. I think this is the answer of your problem:
    https://stackoverflow.com/a/46224576/2056125

    RépondreSupprimer