⌚ Timestamps: 00:00 Introduction 00:59 Create Fresh Laravel APP 02:13 Create Post Model & Migration 03:39 Remove auto-increment IDs 05:39 Add UUID as Primary key 07:41 Auto-generate UUID when creating a post 11:57 Advantages and disadvantages of using UUIDs
Thank you for video. Especially HasUuid trait trick was very helpful :) But if we delete the id field (which is auto incrementing), rows in the table will be not sorted because primary key (uuid) is a char field. To avoid that I recommend you guys to keep id field as it is and add uuid field as additional (instead of removing id field) and give it unique attribute. Then in your model, only use the HasUuid trait and add following part of code for route model binding and remove other declarations of variables in this video (such as $primaryKey); public function getRouteKeyName() { return 'uuid'; } In this way you gonna have id and uuid fields at the same time. id still will be primary key and auto incrementing, but because of route model binding feature, you will be able to use uuid's in links.
Thanks for taking the time to do put the video together. I think you should add what do to if you have a live application and would want to change or "convert" the id field to a UUID field.
This is an old video, but as a complementary, instead of using a cycle listener to generate the UUID at Post creation, we could just do it from the native DB function from the migration itself: $table->uuid('uuid')->index()->default(DB::raw('(UUID())')); As well as making this column as an index. Thanks.
I didn't know about it thanks for sharing 1 more change which is casting because how you can get the id of newly created record like $product->id solution is casting. and what about your thoughts if we drop "primary id auto increment"? according to my experiment never drop primary id, instead make 2nd column called uuid or external_id of uuid dattype char(36). I know its not because of db storage but think about if any primary_id delete suppose 5, then new record id will be 6 but in case of uuid you can use the uuid of delete row because uuid is not set primary. Even if we set uuid column as primary with auto_increment off then we can face same issue.
Instead of a trait, I prefer to create a parent model with $incrementing, $primaryKey, and $keyType declarations and a static boot function, that assigns uuid to the primary key (Str::uuid()->toString()). After that, it is enough to inherit this parent model :)
for the love of God - use shortcuts so u dont have to type full php artisan migrate etc instead a:m or something else.. we dont need to see you type the whole thing - applies to everyone not just this video
⌚ Timestamps:
00:00 Introduction
00:59 Create Fresh Laravel APP
02:13 Create Post Model & Migration
03:39 Remove auto-increment IDs
05:39 Add UUID as Primary key
07:41 Auto-generate UUID when creating a post
11:57 Advantages and disadvantages of using UUIDs
Thank you for video. Especially HasUuid trait trick was very helpful :) But if we delete the id field (which is auto incrementing), rows in the table will be not sorted because primary key (uuid) is a char field. To avoid that I recommend you guys to keep id field as it is and add uuid field as additional (instead of removing id field) and give it unique attribute. Then in your model, only use the HasUuid trait and add following part of code for route model binding and remove other declarations of variables in this video (such as $primaryKey);
public function getRouteKeyName()
{
return 'uuid';
}
In this way you gonna have id and uuid fields at the same time. id still will be primary key and auto incrementing, but because of route model binding feature, you will be able to use uuid's in links.
I appreciate this, Good info. Thanks for sharing your thoughts.
Thanks for taking the time to do put the video together. I think you should add what do to if you have a live application and would want to change or "convert" the id field to a UUID field.
thanks so much sir
savior. Tahnk you
Glad you like it!
This is an old video, but as a complementary, instead of using a cycle listener to generate the UUID at Post creation, we could just do it from the native DB function from the migration itself: $table->uuid('uuid')->index()->default(DB::raw('(UUID())'));
As well as making this column as an index.
Thanks.
I didn't know about it thanks for sharing 1 more change which is casting because how you can get the id of newly created record like $product->id solution is casting. and what about your thoughts if we drop "primary id auto increment"? according to my experiment never drop primary id, instead make 2nd column called uuid or external_id of uuid dattype char(36). I know its not because of db storage but think about if any primary_id delete suppose 5, then new record id will be 6 but in case of uuid you can use the uuid of delete row because uuid is not set primary. Even if we set uuid column as primary with auto_increment off then we can face same issue.
Best video of uuid !! thanks!!
Thanks
Thank you so much. You explained very easily.
You are welcome!
thank you
Welcome
Lol
Muchas gracias amigo! Buena explicación
Thank you 😊
Amazing Video! Very interesting topic. Keep going!
Can I know what is your terminal and Vs theme?
Thanks
very nice
i do have table user and profile, does both of them need uuid or only profile ?
amazing videos. Thanks for sharing it :)
Glad you like them!
Thanks 😊
You're welcome!
Nice and easy to follow video, thanks - do you have a video how you configured your visual studio code for laravel development?
Not yet! I will create video on this as well.
Instead of a trait, I prefer to create a parent model with $incrementing, $primaryKey, and $keyType declarations and a static boot function, that assigns uuid to the primary key (Str::uuid()->toString()). After that, it is enough to inherit this parent model :)
That is also a good solution.
love you 3000
Thank you so much
Need help!!!! take 1hour to import 50k records laravel matwebsite package what to do??THanks
You should use Laravel queue for that. I will create video on this as well.
wawwwwwwwwwwww thanks
Glad you like them!
Hiii sir
Hello
I ask a question about
Crack APK
UUID should be string and not class. Replace `Str::uuid()` to `Str::uuid()->toString()`
for the love of God - use shortcuts so u dont have to type full php artisan migrate etc instead a:m or something else.. we dont need to see you type the whole thing - applies to everyone not just this video