php[tek] 2026 in Chicago focuses on modern PHP practices. UUID v7 sessions address the practical shift from auto-increment IDs and UUID v4 to time-ordered RFC 9562 identifiers in production Laravel and Symfony applications. See UUID in PHP and Laravel for the implementation context.
Laravel Eloquent with UUID v7
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class Order extends Model
{
use HasUuids; // Tells Eloquent to use UUID as primary key
protected $keyType = 'string';
public $incrementing = false;
// Override to use UUID v7 instead of v4
public function newUniqueId(): string
{
return (string) Str::uuid7(); // UUID v7 — time-ordered
}
}
// Usage
$order = Order::create([
'customer_id' => $customerId,
'total' => 99.99,
'status' => 'pending',
]);
Symfony + Doctrine ORM
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity]
#[ORM\Table(name: 'orders')]
class Order
{
#[ORM\Id]
#[ORM\Column(type: 'uuid')]
private Uuid $id;
public function __construct(
#[ORM\Column(type: 'uuid')] private Uuid $customerId,
#[ORM\Column] private float $total,
) {
$this->id = Uuid::v7(); // UUID v7 — millisecond-ordered
}
public function getId(): Uuid { return $this->id; }
}
Cursor pagination with PDO
function listOrders(PDO $pdo, ?string $cursor = null, int $limit = 20): array
{
if ($cursor) {
$stmt = $pdo->prepare(
'SELECT id, total, status FROM orders WHERE id > ? ORDER BY id LIMIT ?'
);
$stmt->execute([$cursor, $limit]);
} else {
$stmt = $pdo->prepare(
'SELECT id, total, status FROM orders ORDER BY id LIMIT ?'
);
$stmt->execute([$limit]);
}
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
$nextCursor = count($items) === $limit ? end($items)['id'] : null;
return compact('items', 'nextCursor');
}
Further reading
External references
Frequently asked questions
How do I generate UUID v7 in PHP?
Use the symfony/uid package: $id = (string) Uuid::v7(). Laravel 11+ ships Str::uuid7() via the ramsey/uuid integration. For standalone use, install composer require ramsey/uuid and call Uuid::uuid7()->toString(). See UUID in PHP for the full guide.
How does UUID v7 work as a primary key in Laravel Eloquent?
Add use HasUuids to your Eloquent model. Override the newUniqueId() method to return Str::uuid7() instead of the default UUID v4. Your migration stays the same — the column type remains uuid in PostgreSQL or char(36) in MySQL. Time-ordering improves B-tree index locality. See UUID in PHP and Laravel.
How do I use UUID v7 with Doctrine ORM in Symfony?
Set the Doctrine entity ID column to #[ORM\Column(type: 'uuid')] and generate in the constructor: $this->id = Uuid::v7(). The symfony/uid package provides the UuidType Doctrine type. Symfony's Uuid value object implements __toString() for query parameters. See UUID in PostgreSQL.