问题
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));
}
}
回答1:
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">
回答2:
I think we can add custom fields, Here are steps which I figure out to add custom fields.
1 - add input
field in register view.
i.e. <input type="email" name="you_custome_field">
2 - open app/services/Registrar.php and register you custom fied in create function.i.e.
public function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'you_custome_field' => $data['you_custome_field'],
]);
}
3 - (optional) Open user model
app/User.php register you field as guarded
or fillable
as you want.
I hope this will work.
来源:https://stackoverflow.com/questions/27757723/laravel-reset-password-using-different-column-name