mykemeynell / laraveluuid
This package is abandoned and no longer maintained.
No replacement package was suggested.
There is no license information available for the latest version (1.0.3) of this package.
UUID column functionality for Laravel projects
1.0.3
2020-07-23 18:06 UTC
Requires
- php: >=7.1.0
- ramsey/uuid: ^4.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-02 15:03:51 UTC
README
Easily start using UUID within your Laravel application, rathern than the default auto incrementing ID.
Install with Composer
composer require mykemeynell/laraveluuid
Usage
- Add a UUID column into your migration, for example the default "create users" migration.
use ...; class CreateUsersTable extends Migration { // Include the UuidColumn trait into your migration class. // This will give you access to the necessary method to easily // create the appropriate column. use \UuidColumn\Concern\UuidColumn; public function up() { Schema::create('users', function(Blueprint $table) { // Calling the createUuidColumn() method will add the column into your migration. // You can migrate this normally with PHP Artisan. $this->createUuidColumn($table, 'id); ...
- Add the
HasUUidObservertrait to your Model. For example, on the default User model atapp/User.php.
use ...; use UuidColumn\Concern\HasUuidObserver; class User extends Authenticatable { use ..., HasUuidObserver; ...
- You'll need to change the defaults in the model to reflect the new key type and behaviour:
class User extends Authenticatable { ... /** * Indicates if the IDs are auto-incrementing. * * @var bool */ public $incrementing = false; /** * The "type" of the primary key ID. * * @var string */ protected $keyType = 'string'; ...
That's it! When new records are created, a new UUID4 string will be set at the ID.