laravel 5.4更改身份验证用户表名称 [英] laravel 5.4 change authentication users table name

查看:88
本文介绍了laravel 5.4更改身份验证用户表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在我的应用程序中使用 laarvel5.4 身份验证;我想更改用户表名,同时保持其在身份验证逻辑中的作用,我只需要更改名称即可.

I'm currently using the laarvel5.4 authentication in my application; and I want to change the users table name while keeping its role as it is in the authentication logic, all I need is just to change the name.

Laravel似乎会在最新版本中更改Auth文件和代码结构,因此auth.php看起来并不像laravel的先前版本中一样.

It seems that Laravel changer the Auth file and code structure in the latest version, so auth.php doesn't really look as in the previous versions of laravel.

到目前为止,我已经完成了以下操作,但是仍然无法正常工作,给我一个错误,指出表用户不存在:

I have done the following so far, but it's still not working gy giving me an error saying that the table users doesn't exist:

  • 1-我已经更改了迁移 up() down()功能,以创建并删除 staff 表而不是 users 用户,并成功运行迁移.
  • 2-我已经更改了 RegisterController 中的 validator()函数.

  • 1- I have changed the migration's up() and down() functions to create and drop staff table instead of users and run the migration successfully.
  • 2- I have changed the validator() function in RegisterController.

3-我已在 config/auth.php中将所有'用户'更改为'staff' ,如代码所示:

3- I have changed all the 'users' to 'staff' in config/auth.php, as shown in the code:

 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 到新的表名,但是在我的课程中我没有这样的东西

However, in app/User.php I don't know what to change since in the previous versions there used to be a table variable which u need to change its value from users to the new table name but in my class I don't have such thing

<?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',
    ];
}

推荐答案

您可以在迁移中更改表名

You can change the table name in the migration file and then change the table name variable in the User.php model.

示例:

class Flight extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'my_flights';
}

https://laravel.com/docs/5.4/eloquent#eloquent-模型惯例

这篇关于laravel 5.4更改身份验证用户表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆