nevadskiy / laravel-uuid
The package provides UUID keys functionality for Eloquent models with one single trait.
Installs: 3 073
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^7.3|^8.0
- illuminate/database: ^7.0|^8.0|^9.0
- ramsey/uuid: ^3.7|^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0
- phpunit/phpunit: ^8.0|^9.0
README
Laravel UUIDs
The package allows models to use UUID primary keys with one single trait.
Installation
Install a package via composer.
composer require nevadskiy/laravel-uuid
Usage
Add a trait to your model, and it will automatically assign a UUID key to the model during creation.
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Nevadskiy\Uuid\Uuid; class Product extends Model { use Uuid; }
Set up migrations to use UUID primary keys.
Schema::create('products', function (Blueprint $table) { $table->uuid('id')->primary(); });
Recommendations
Set up the default field type for database migrations when using the morphs
method.
public function boot(): void { Builder::morphsUsingUuid(); }
You can also use the parameter expression constraints for routes that use a route model binding.
Route::get('/products/{product}', '...')->whereUuid('product')
Requirements
- Laravel
6.0
or newer - PHP
7.2
or newer
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Any contribution is Welcome.
Please see CONTRIBUTING for more information.
Security
If you discover any security related issues, please e-mail me instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE for more information.