bmatovu / laravel-eloquent-uuid
Laravel Eloquent UUID.
Installs: 7 440
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
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
THIS PACKAGE IS NOT MAINTAINED ANYMORE...
LARAVEL HAS INTRODUCTED UUID & ULID SUPPORT IN THE CORE STARTING WITH LARAVEL V9
https://laravel.com/docs/9.x/eloquent#uuid-and-ulid-keys
Laravel Eloquent UUID.
Installation
Install via Composer package manager:
composer require bmatovu/laravel-eloquent-uuid
Usage
Migration:
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'); }); } }
Model:
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; }
Testing
Factories fail after faking events: (Issue #19952)
After calling Event::fake()
, no event listeners will be executed. So, if your tests use model factories that use the HasUuidKey
trait; you should call Event::fake() after using your factories.