I am trying to authenticate users with a table different from 'users', which is the default Laravel, my table fields are called different in this case "mail" and "password"
I can not do the authentication because I do not recognize the field "password" I only manage to login when the field is called "password"
Is there any way to change this so that I recognize the "password" field? I already tried implementing the getAuthPassword method but it did not work for me.
I have the following code in the LoginController
class LoginController extends Controller
{
// funcion que solo permite dejar pasar al usuario a la rutas si hace sesion
public function __construct()
{
//$this->middleware('guest')->except('logout');
$this->middleware('guest', ['only' => 'showLoginForm']);
}
// retorna a vista login
public function showLoginForm(){
return view('login');
}
// funcion para inciar sesion
public function login(){
$datos = $this->validate(request(), [
$this->username() => 'email|required|string',
$this->getAuthPassword() => 'required|string'
]);
// valida si lo datos son correctos crea la sesion
if (Auth::attempt($datos)) {
return redirect('ventas');
}
// si son incorrectos devuelve un mensaje
return back()
->withErrors([$this->username() => trans('auth.failed')])
->withInput(request([$this->username()]));
//return $this->getAuthPassword();
}
// funcion para cerrar sesion
public function logout(){
// cierra sesion y devuelve al login
Auth::logout();
return redirect('/');
}
public function getAuthPassword () {
return "contrasena";
}
public function username(){
return "correo";
}
}
The following code in the User.php model
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $table = 'usuarios';
protected $fillable = [
'nombres', 'correo', 'contrasena',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}