Description
Laravel Version
11.33.2
PHP Version
8.3
Database Driver & Version
mariadb:11.4
Description
I use uuid as primary key instead of integer. I changed type in migration file $table->uuid('id')->primary(); and added Illuminate\Database\Eloquent\Concerns\HasUuids trait to the model.
When I fill the table with data and do sorting by id the records are not sorted in correct way. I see that HasUuids trait calls Str::orderedUuid() method which calls $factory->uuid4(). If i understood correct the v4 generates random uuid.
The documentation says
By default, The HasUuids trait will generate "ordered" UUIDs for your models. These UUIDs are more efficient for indexed database storage because they can be sorted lexicographically.
Looks like orderedUuid method should use v7 instead of v4.
Steps To Reproduce
Create a migration
Schema::create('records', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('title');
$table->timestamp('created_at');
$table->timestamp('updated_at');
});
Create a model with HasUuids trait
class Record extends Model
{
use \Illuminate\Database\Eloquent\Concerns\HasUuids;
}
Create a N records to fill the table. The sorting by id should be equivalent sorting by created_at but it doesn't.