Home > Backend Development > PHP Tutorial > Laravel更改登录时使用的默认字段名称email

Laravel更改登录时使用的默认字段名称email

WBOY
Release: 2016-06-23 13:18:23
Original
1444 people have browsed it

Laravel 自带的认证系统中,登录时使用 email与 password来认证用户,其实 Laravel 提供了一个属性来替换默认的 email字段,可以在 AuthController中添加下面的属性即可实现:

protected $username = 'name';  // 数据库中字段的名称
Copy after login

此外,还需要修改登录视图中相应的字段名称。

可以在 /vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php文件中看到  loginUsername()方法会优先查找该字段,如果没有设置的话,默认使用 email字段。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template