Illuminate\Support\Str::uuid()), this package does not generate UUIDs—it only encodes/decodes. For a complete UUID lifecycle, pair it with ramsey/uuid or symfony/uuid.ramsey/uuid (v4.1+) is a force multiplier—if the project already uses Ramsey UUID, integration is plug-and-play. If not, the 1KB overhead is justified for standardization.// PostgreSQL: CHAR(36) → VARCHAR(32) for encoded UUIDs
Schema::table('events', function (Blueprint $table) {
$table->string('encoded_uuid')->unique()->nullable();
});
EventSauce\UuidEncoding\UuidEncoder) ensures native integration with event metadata, stream names, or event IDs.^1.0) to avoid breaking changes.ramsey/uuid) or encoded (this package)? Clarify the lifecycle (generate → encode → store).ramsey/uuid? If not, budget 1–2 hours for adoption.UuidEncoder to Laravel’s DI container for dependency injection:
$this->app->singleton(UuidEncoder::class, fn() => new UuidEncoder());
stream_name, event_id).VARCHAR(32) (vs. CHAR(36) for raw).String type with encoded format.Phase 1: Dependency Setup
composer.json:
"require": {
"ramsey/uuid": "^4.1",
"eventsauce/uuid-encoding": "^1.0"
}
composer update.Phase 2: Core Integration
UuidEncoder to the container (see Stack Fit).// app/Helpers/UuidHelper.php
function encodeUuid(UuidInterface $uuid): string
{
return app(UuidEncoder::class)->encode($uuid);
}
function decodeUuid(string $encoded): UuidInterface
{
return app(UuidEncoder::class)->decode($encoded);
}
Phase 3: Domain-Specific Integration
$event = new UserRegistered(
id: encodeUuid($uuid),
email: "user@example.com"
);
$eventStore->append($streamName, $event);
class User extends Model
{
protected $casts = ['id' => 'string']; // Store as encoded string
public function getIdAttribute($value)
{
return decodeUuid($value);
}
public function setIdAttribute($value)
{
$this->attributes['id'] = encodeUuid($value);
}
}
return response()->json([
'id' => encodeUuid($user->id),
'name' => $user->name
]);
Phase 4: Database Migration
Schema::table('users', function (Blueprint $table) {
$table->string('encoded_id')->unique()->nullable();
});
User::chunk(100, function ($users) {
foreach ($users as $user) {
$user->update(['encoded_id' => encodeUuid($user->id)]);
}
});
ramsey/uuid usage.ramsey/uuid). Ensure your app’s UUID generation aligns.\InvalidArgumentException. Add validation:
try {
$uuid = decodeUuid($encoded);
} catch (\InvalidArgumentException $e) {
Log::error("Invalid UUID: {$encoded}");
throw new \RuntimeException("Invalid UUID format");
}
null or empty strings in database/API layers.UserRegistered) before rolling out.ramsey/uuid.How can I help you explore Laravel packages today?