Laravel Password Reset is not working with Customized User model

Asked

Viewed 195 times

1

I am trying to use the Laravel authentication system with some customizations.

This is my User model:

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\DB;

class Usuario extends Authenticatable
{
    use Notifiable;

    protected $table = 'csrh.usuarios'; 

    protected $fillable = [
        'nm_completo',
        'username',
        'password',
        'tp_usuario',
        'status_usuario'
    ];

    protected $hidden = [
        'password'
    ];

    public $timestamps = false;    

    public function servidor()
    {
        return $this->hasOne('CSRH\Servidor', 'id_usuario');
    }    

    public function getEmailForPasswordReset() {            
        return $this->servidor->e_mail;
    }        

    /**
     * Overrides the method to ignore the remember token.
     */
    public function setAttribute($key, $value)
    {
        $isRememberTokenAttribute = $key == $this->getRememberTokenName();
        if (!$isRememberTokenAttribute) {
            parent::setAttribute($key, $value);
        }
    }

}

The user’s email is in the table 'server', in the e_mail field.

When I click the 'Reset password' button, I get the following error:

SQLSTATE[42703]: Undefined column: 7 ERRO: coluna "email" não existe
LINE 1: select * from "csrh"."usuarios" where "email" = $1 limit 1
^ (SQL: select * from "csrh"."usuarios" where "email" = 
[email protected] limit 1)

I tried to implement the Canresetpassword contract but fell into the same problem.

Any idea?

  • Welcome, this problem is because you don’t have the spine email in your table, in the database, you must create it.

  • Thank you! Although this solves the problem, it is a solution that I would not like to use, not to generate redundancy in my database.

  • You are using Migrações ?

  • Put the controller on.

  • @Peel Only the migration to the table password_resets, no changes.

  • @Diegosouza am using the authentication controllers that comes with Laravel, no changes.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.