【发布时间】:2017-11-10 22:58:15
【问题描述】:
我目前在我的应用程序中使用 laarvel5.4 身份验证;我想更改用户表名称,同时保持其在身份验证逻辑中的角色,我只需要更改名称即可。
Laravel 似乎改变了最新版本的 Auth 文件和代码结构,所以 auth.php 看起来不像以前版本的 laravel。
到目前为止,我已经完成了以下操作,但仍然无法正常工作,给我一个错误,说表用户不存在:
- 1- 我已经更改了 migration 的 up() 和 down() 函数来创建和删除 staff 表而不是 users 并成功运行迁移。
2-我已更改RegisterController中的validator()函数。
-
3- 我已将 config/auth.php 中的所有 'users' 更改为 'staff' >,如代码所示:
return [ 'defaults' => [ 'guard' => 'web', 'passwords' => 'staff', ], 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'staff', ], 'api' => [ 'driver' => 'token', 'provider' => 'staff', ], ], 'providers' => [ 'staff' => [ 'driver' => 'eloquent', 'model' => App\User::class, ], // 'staff' => [ // 'driver' => 'database', // 'table' => 'staff', // ], ], 'passwords' => [ 'staff' => [ 'provider' => 'staff', 'table' => 'password_resets', 'expire' => 60, ], ],];
但是,在 app/User.php 我不知道要更改什么,因为在以前的版本中曾经有一个 table 变量,您需要更改它它的值从 users 到新表名,但在我的课堂上我没有这样的东西
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
【问题讨论】:
标签: laravel authentication laravel-5.4