更多python、PHP教程请到友情连接: 菜鸟教程https://www.piaodoo.com
茂名一技http://www.enechn.com
ppt制作教程步骤 http://www.tpyjn.cn
兴化论坛http://www.yimoge.cn
电白论坛 http://www.fcdzs.com
做项目的时候,用户认证几乎是必不可少的,如果我们的项目由于一些原因不得不使用 users 之外的用户表进行认证,那么就需要多做一点工作来完成这个功能。
现在假设我们只需要修改登录用户的表,表名和表结构都与框架默认的表users不同,文档没有教我们如何去做,但是别慌,稍微看下框架实现用户认证的源码就能轻松实现。
首先,自定义一张表用来登录,表结构和模拟数据如下:
表 admins
id | login_name | login_pass |
---|---|---|
1 | admin | 2y10$2MUhp7b6ghVOngb/.b/x6uuEW/yL3FqPKJztawrM0U577Clf07xda |
从配置文件入手
用户认证相关的配置都保存在config/auth.php文件中,先来看看配置文件的内容:
<?php
return [ /* |-------------------------------------------------------------------------- | Authentication Defaults |-------------------------------------------------------------------------- | | This option controls the default authentication "guard" and password | reset options for your application. You may change these defaults | as required, but they're a perfect start for most applications. | */ 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], /* |-------------------------------------------------------------------------- | Authentication Guards |-------------------------------------------------------------------------- | | Next, you may define every authentication guard for your application. | Of course, a great default configuration has been defined for you | here which uses session storage and the Eloquent user provider. | | All authentication drivers have a user provider. This defines how the | users are actually retrieved out of your database or other storage | mechanism