7
I tried everything already, but I can’t solve a problem in the login system 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 the Laravel
still treats as model
login pattern to User model, I managed to change this, through this line:
protected $table = 'Usuarios';
Another problem has arisen, of not finding the field password
that was standard (default
), I went to the archive EloquentUserProvider
and changed from password
for Senha
(which is how it is in I bank. However now it does not pass in the Auth::attempt()
. I spent all day looking for some solution, all I tried was in vain).
Model code User
:
<?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 Usuario
:
<?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',
];
}
Code of function logging into 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 already checked if the data is coming from the form correctly and any help is welcome.
I ask: Why change? , for this to work you don’t need to change the base class and authentication can be done differently...
– novic
Virgil, where exactly do I put the code of step 5?
– Erikson Flávio
@Eriksonflávio puts in action controller that will be responsible for logging the user.
– Matheus Picioli