1. 关闭自增长并创建uuid字段(app/User.php)
public $incrementing = false; public static function boot() { parent::boot(); static::creating(function ($model) { $model->{$model->getKeyName()} = (string)Str::uuid(); // use Illuminate\Support\Str; }); }
2. 将模型中的id字段改为uuid(database/migrations/2014_10_12_000000_create_users_table.php)
3. 刷新数据库
php artisan migrate:refresh