I would like to add a custom prefix to UUIDs within Laravel to help keep better track of Database entries. Currently, when called, the uuid(); function will produce a table entry like this:
6ab4a8c-9597-lle7-a63c-0242c100426l
But I would like to be able to a a prefix infront of every uuid entry within that table. For instance, Users within the Users table would have a uuid prefixed with UUID of:
UUID-6ab4a8c-9597-lle7-a63c-0242c100426l
and Posts would be saved in the Posts table with a PUID prefix:
PUID-6ab4a8c-9597-lle7-a63c-0242c100426l
to signify ('Post' Unique Identifier).
The default migration for the Users table is as follows:
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
To use UUIDs, the following would be used:
Schema::create('users', function (Blueprint $table) {
$table->uuid('uuid')->primary();
});
I'm not sure where the models defining UUID(s) are stored, and I'm not sure I'd want to modify the entire model.
Ideally, the a uuid would be defined using the table name, then the prefix as such:
$table->uuid('puid', 'PUID')->primary();
Does anyone know how this could be implemented?
Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire