laravel 使用uuid


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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM