I'm trying to log in to laravel 5.2 but is not authenticating the user to the table.
In the file auth.php
I changed the validation table to login
:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'login',
],
And I've added the Login class:
'providers' => [
'login' => [
'driver' => 'eloquent',
'model' => App\Login::class,
],
I created my Model in App\Login
:
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Login extends Authenticatable
{
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
And in the path Http/Controllers/LoginController.php
I created the controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Auth;
class LoginController extends BaseController
{
public function logar(Request $req) {
$validator = Validator($req->all(), [
'email' => 'required',
'password' => 'required'
]);
if($validator->fails()) {
return redirect('candidato/login')
->withErrors($validator)
->withInput();
}
$credenciais = ['email' => $req->input('email'), 'password' => $req->input('password')];
dd(Auth::attempt($credenciais));
if(Auth::attempt($credenciais, true)) {
return redirect('candidato/perfil');
} else {
return redirect('candidato/login')
->withErrors(['errors' => 'login inválido'])
->withInput();
}
}
}
But it always falls into else
, even though it takes the user to the bank, it does not validate.
dd(Auth::attempt($credenciais));
is always returning false
.
Would anyone know why it does not authenticate?