我目前正在使用 laarvel5.4 在我的应用程序中进行身份验证;并且我想更改用户表名称,同时保持其在身份验证逻辑中的作用,我只需要更改名称即可。
似乎 Laravel 在最新版本中更改了 Auth 文件和代码结构,因此 auth.php 看起来并不像以前版本的 Laravel 那样。
到目前为止,我已经完成了以下操作,但它仍然无法正常工作 gy 给我一个错误,说表用户不存在:
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 我不知道要更改什么,因为在以前的版本中曾经有一个 表您需要更改其值的变量 用户 到新表名,但在我的类(class)中我没有这样的东西
<?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',
];
}
最佳答案
您可以在迁移中更改表名 file然后更改 User.php 中的表名变量模型。
例子:
class Flight extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'my_flights';
}
https://laravel.com/docs/5.4/eloquent#eloquent-model-conventions
关于laravel 5.4 更改认证用户表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44449076/