Skip to content

Instantly share code, notes, and snippets.

@ibayazit
Created October 7, 2022 08:45
Show Gist options
  • Save ibayazit/dabcfd720e7b6e1f3542c7240d35312b to your computer and use it in GitHub Desktop.
Save ibayazit/dabcfd720e7b6e1f3542c7240d35312b to your computer and use it in GitHub Desktop.
Laravel uuid migration. pros and cons : With this way you can create UUID easily but the created user model doesn't return UUID or i couldn't find a way
<?php
...
use Illuminate\Database\Query\Expression;
...
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary()->unique()->default(new Expression('(UUID())'));
...
});
}
...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment