tonoslfx tonoslfx - 6 months ago 102
PHP Question

Laravel Reset Password Using Different Column Name

i managed to make it work when it comes to authorisation with different columns name either username, email or password.

How to change / Custom password field name for Laravel 4 and Laravel 5 user authentication

however the password reminder seems doesnt work.

i have changed the user model, to my table column name.

User Model:

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

use UserTrait, RemindableTrait;

protected $primaryKey = 'user_id';
protected $table = 'user';

public function getReminderEmail() {
return $this->user_email;
}

public function getAuthPassword() {
return $this->user_pwd;
}

public function getRememberTokenName() {
return 'user_token';
}

}


User Controller

Auth::attempt( array(
'user_name' => $username,
'password' => $password
), TRUE );


Reminder Controller // Error: Column email not found
(Not sure, its not reading the user model getReminderEmail())

public function post_reminder() {

switch ($response = Password::remind(Input::only('email'))) {

case Password::INVALID_USER:
return Redirect::back()->with('error', Lang::get($response));

case Password::REMINDER_SENT:
return Redirect::back()->with('status', Lang::get($response));
}


}

Answer

Took me hours to figure it out. Laravel official doesnt seems give a proper documentation to implement the custom name field.

We just need to change the input field name the same with your table column name.

Field could be anything
<input type="email" name="user_email">
Comments