I have tried everything already, but I can not solve a problem with the login system of Laravel
which is this: I created a model called Usuarios
, I put all the information in it that has to be properly placed, like the array $fillable
and $hidden
, however internally Laravel
still treats as model
default login to User model, I was able to change this, through this line:
protected $table = 'Usuarios';
There was another problem, not finding the password
field that was default ( default
), I went to the file EloquentUserProvider
and changed from password
to Senha
( I've been looking for some solution, all I tried was in vain.)
Model code Auth::attempt()
:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $model = 'Usuario';
protected $increments = false;
protected $table = 'Usuarios';
protected $primaryKey = 'UsuarioID';
public function getAuthIdentifier() {
return $this->getKey();
}
public function getAuthPassword() {
return $this->Senha;
}
public function getReminderEmail() {
return $this->Login;
}
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
Model code User
:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Usuario extends Authenticatable
{
use Notifiable;
/*protected $model = 'Usuario';
protected $increments = false;
protected $table = 'Usuarios';
protected $primaryKey = 'UsuarioID';
public function getAuthIdentifier() {
return $this->getKey();
}
public function getAuthPassword() {
return $this->Senha;
}
public function getReminderEmail() {
return $this->Login;
}*/
protected $fillable = [
'UsuarioID', 'Nome', 'Login', 'Senha'
];
protected $hidden = [
'Senha', 'remember_token',
];
}
Function code that logs into the controller:
public function entrar(Request $request)
{
$dadosFormulario=$request->all();
$dadosLogin=['Login'=>$dadosFormulario['login'],'Senha'=>$dadosFormulario['senha']];
if( dd(Auth::attempt($dadosLogin)) ){
return redirect()->route('admin.cursos');
} else {
return redirect()->route('site.home');
}
}
Here I have checked if the data is coming correctly from the form and any help is welcome.