Homepage
Main navigation
Main content
Additional information
October Tricks
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
October CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
Using UUIDs in your database tables is easier than it seems. Here are the steps you should take to ensure that October CMS works properly with UUID columns. ## Migrations The schema builder comes with a handy `uuid` table column that we can use to place our UUIDs. You'll also need to append `primary()` to ensure that the UUID becomes the primary key. ```php // updates/create_table.php Schema::create('my_database_table', function (Blueprint $table) { $table->uuid('id')->primary(); }); ``` ## Models In your models, set the `$incrementing` variable to `false` to ensure that the Model does not increment the value of the UUID. Finally, automatically generating a UUID will require the `Ramsey\Uuid\Uuid`. We'll be using this library because it already comes installed with Laravel, so there's no need to install any other UUID generator. Next, add the `beforeCreate()` event method into your Model. The code to generate the UUID is: ```php use Ramsey\Uuid\Uuid; class Test extends Model { public $incrementing = false; public function beforeCreate() { $this->id = Uuid::uuid4()->toString(); } } ``` You can learn more about the UUID library on [GitHub](https://github.com/ramsey/uuid).
References
Add additional online resources to your trick
×
Name
URL
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline