bmatovu / laravel-eloquent-uuid
该包已被弃用,不再维护。未建议替代包。
Laravel Eloquent UUID。
v1.1.0
2021-03-20 19:08 UTC
Requires
- php: >=5.6.4
- illuminate/database: ^5.3|^6.0|^7.0|^8.0
- illuminate/support: ^5.3|^6.0|^7.0|^8.0
- ramsey/uuid: ^3.0|^4.0
Requires (Dev)
- fzaninotto/faker: ^1.9
- laravel/framework: ^8.0
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3.3
This package is auto-updated.
Last update: 2023-03-01 06:54:04 UTC
README
该包已不再维护...
Laravel 从 V9 版本开始已在核心中引入了 UUID & ULID 支持
https://laravel.net.cn/docs/9.x/eloquent#uuid-and-ulid-keys
Laravel Eloquent UUID。
安装
通过 Composer 包管理器安装
composer require bmatovu/laravel-eloquent-uuid
使用方法
迁移:
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateClientsTable extends Migration { public function up() { Schema::create('clients', function (Blueprint $table) { $table->uuid('id'); $table->string('name'); // ... $table->timestamps(); $table->primary('id'); }); } }
模型:
use Bmatovu\Uuid\Traits\HasUuidKey; use Illuminate\Database\Eloquent\Model; class Client extends Model { use HasUuidKey; /** * The "type" of the primary key ID. * * @var string */ protected $keyType = 'string'; /** * Indicates if the IDs are auto-incrementing. * * @var bool */ public $incrementing = false; }
测试
事件伪造后工厂失败: (问题 #19952)
调用 Event::fake()
后,将不会执行任何事件监听器。因此,如果您的测试使用使用 HasUuidKey
特性的模型工厂;您应该在使用工厂后调用 Event::fake()。