我正在尝试将 Laravel 的默认表名从其模型名称和复数更改为另一个自定义名称。通过阅读,我认为我必须在 app/Model/User.php 中更新它,例如然后完成。但不幸的是它不起作用。这是我通过将 users 表更改为 web_registration 表的尝试:
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
*@var string[]
**/
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'web_registration';
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
但是当我运行迁移时,我仍然得到用户表而不是 web_registration 表。请注意,我还按照其他堆栈答案的建议运行了 composer dump-autoload -o ,但仍然没有任何更改。还有其他地方我需要更改吗?