laravel 修改laravel 5.1登录使用用户名而不是电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31211153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
modify laravel 5.1 login to use username instead of email
提问by Chriz74
This function is responsible of defining the username in laravel 5.1 authentication:
这个函数负责定义laravel 5.1认证中的用户名:
public function loginUsername()
{
return property_exists($this, 'username') ? $this->username : 'email';
}
if I modify it to
如果我将其修改为
public function loginUsername()
{
return property_exists($this, 'username') ? $this->username : 'username';
}
in the foundation file (and adapt my views and db) will this persist in the event of an update? and if not how do I override it and leave the foundation file alone? I already made a new controller for registering user and I am calling it in my route instead of the default one, however I am finding difficult to do the same with the postlogin route.
在基础文件中(并调整我的视图和数据库)这会在更新时持续存在吗?如果不是,我该如何覆盖它并单独保留基础文件?我已经创建了一个用于注册用户的新控制器,我在我的路由中调用它而不是默认控制器,但是我发现很难对 postlogin 路由执行相同的操作。
回答by Jim M
Instead of modifying that in AuthenticatesUsers
trait, you just have to add a property on your AuthController
:
AuthenticatesUsers
您只需在trait 上添加一个属性,而不是在trait中修改它AuthController
:
protected $username = 'username';
protected $username = 'username';