mindtwo / laravel-auto-create-uuid
Laravel Auto Create UUID
Installs: 6 484
Dependents: 4
Suggesters: 0
Security: 0
Stars: 2
Watchers: 6
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^7.0|^8.0|^8.1
- illuminate/support: ^7.4|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.2|^8.0
- phpunit/phpunit: ^9.0|^10.0
README
Installation
You can install the package via composer:
composer require mindtwo/laravel-auto-create-uuid
How to use?
Prepare eloquent model
Simply use the AutoCreateUuid trait in your eloquent model.
namespace example; use Illuminate\Database\Eloquent\Model; use mindtwo\LaravelAutoCreateUuid\AutoCreateUuid; class Example extends Model { use AutoCreateUuid; }
Add UUID column to migration
Make sure to add the column in your migration file.
$table->string('uuid', 36)->unique();
Customize UUID attribute
The default attribute name for the auto generated UUID is 'uuid'. However you can customize it, if you need. There are two possibilities to do so.
Either you set up a property named 'uuid_column':
namespace example; use Illuminate\Database\Eloquent\Model; use mindtwo\LaravelAutoCreateUuid\AutoCreateUuid; class Example extends Model { use AutoCreateUuid; protected $uuid_column = 'id' }
or you overload the getUuidColumn() method:
namespace example; use Illuminate\Database\Eloquent\Model; use mindtwo\LaravelAutoCreateUuid\AutoCreateUuid; class Example extends Model { use AutoCreateUuid; /** * Get the column name for uuid attribute. * * @return string */ public function getUuidColumn(): string { return 'id'; } }
In both cases the attribute name for the UUID is now 'id' instead of 'uuid'.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email info@mindtwo.de instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.