michaeldyrynda / laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models
MIT License
442 stars 46 forks source link

Using with PostgreSQL uuid data type #91

Closed nathan-io closed 4 years ago

nathan-io commented 4 years ago

Thank you for this great package!

We're using PostgreSQL, which has a uuid data type that stores the value as bytes.

We've manually prepared a migration which includes a uuid field in our model:

Schema::table('users', function (Blueprint $table) {
    $table->uuid('uuid')->index();
});

After running the migration on our Postgres database, our uuid column data type is uuid as desired.

My question is, do we still need to cast our uuid field? If so, can we simply copy the custom cast from michaeldyrynda/laravel-efficient-uuid?

nathan-io commented 4 years ago

Update: It appears to be working fine without any cast.

After adding GeneratesUuid to our User model, I created a new user. It has a valid UUID.

In the Nova admin panel, I can see the UUID displayed as a string. And I'm able to retrieve the new record with User::whereUuid() in Tinker.

So everything seems to be working nicely out of the box on Laravel 7 with Postgres 12, without casting and using Laravel's standard uuid method in the migration.