Reputation: 552
I was reading Laravel's documentation that I noticed Laravel 7 offers a uuid type in the page for database migrations
Unfortunately I couldn't find much information about using it in the documentation. How is such a column filled when I insert a new record? Does Laravel fill it on its own? Does Laravel guarantee it to be unique or should I worry about collisions? Can I use this field to create short links for the posts of a blog, for example?
Upvotes: 0
Views: 349
Reputation: 1856
Laravel should fill this on its own by setting the keyType
(untested) on your model:
protected $keyType = 'string';
The key, whether you fill it manually or not, is unique as laravel depends on Ramsey.
To manually acquire a uuid you may use the provided helper:
use Illuminate\Support\Str;
return (string) Str::uuid();
Upvotes: 1