I am trying to make a guard in laravel 5.2, but when I make the attempt it doesn't work it always return false, even if a don't Hash the password.
This is my guards config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admin',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
providers config/auth.php
'providers' => [
'admin' => [
'driver' => 'eloquent',
'model' => App\Administrator::class,
],
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
],
My model
use Illuminate\Foundation\Auth\User as Authenticatable;
class Administrator extends Authenticatable
{
protected $table = 'administratorsTable';
protected $primaryKey = 'admID';
protected $fillable = [
'admEmail', 'admName', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
public function setPasswordAttribute($valor){
if(!empty($valor)){
$this->attributes['password'] = \Hash::make($valor);
}
}
}
This is my controller, if I change the "admin" to he default guard "web" it acctually works fine!, (Changing also the fileds' names). I cant understand why it doesn't return true.
if (Auth::guard('admin')->attempt([
'admEmail' => $request['email'],
'password' => $request['password']
])) {
return "Welcome";
}else{
return "Fuuuuuuuuuck";
}
I have also tried to use the login fucion with:
use AuthenticatesUsers;
public function loginUsername()
{
return property_exists($this, 'username') ? $this->username : 'admEmail';
}
protected $guard = 'admin';
public function authenticated()
{
return "Welcome";
}
And if I change again the fields for the "web"guard it works fine.
via Saucyloco