Id, IdContract, IdGenerator), suggesting it enforces a consistent ID schema across applications (e.g., UUID, ULID, or custom formats). This aligns well with:
boson-php/boson implies this is a low-level dependency for ID handling, decoupled from business logic. This reduces coupling if the broader boson framework is not used.string/int IDs by default, but this package could enforce strong typing (e.g., Id objects) or custom ID generation (e.g., ULID for time-sorted IDs).Id wrapper for Eloquent models).IdGenerator implementations.CastsAttributes to convert Id objects to/from DB storage.Builder macros to filter by Id objects.Id objects to strings in JSON responses (via JsonSerializable or API resources).CHAR(26) for ULID).id field with a custom Id type requires schema migrations and model updates.boson-php/boson is later adopted, this package’s interfaces must remain backward-compatible.HasUuids or HasUlids packages suffice?IdGenerator be seeded?Id objects be cached in memory (e.g., via Laravel’s app() container)?boson-php/boson adds ID-related features later?CastsAttributes to serialize Id objects to DB storage.
use Boson\IdContracts\Id;
use Illuminate\Database\Eloquent\Casts\Attribute;
protected function id(): Attribute {
return Attribute::make(
get: fn (Id $id) => $id->value(),
set: fn (string $value) => new Id($value),
);
}
JsonSerializable or API resources to expose IDs as strings.Builder macros for Id-based filtering:
use Illuminate\Database\Eloquent\Builder;
Builder::macro('whereId', function (Builder $query, Id $id) {
return $query->where('id', $id->value());
});
spatie/laravel-activitylog (for UUIDs) or nWidart/absolutepath (for path-based IDs).Id trait if the package’s abstractions are overkill.Id objects in application logic (e.g., DTOs, services).CastsAttributes to read/write Id objects without altering the DB.class User extends Model {
protected $casts = ['id' => Id::class];
}
Model::incrementing(false) and use IdGenerator for new records.Id::fromString()) in API controllers.Id-aware macros.CHAR/VARCHAR for ULID/UUID.int/string IDs (e.g., laravel-debugbar).Id serialization in cached/queued jobs.| Step | Priority | Effort | Risk |
|---|---|---|---|
Add Id casting to models |
High | Low | Low |
Update API responses to use Id |
Medium | Medium | Low |
| Replace ID generation in factories/seeds | Low | High | Medium |
| Migrate DB schema (if needed) | Low | High | High |
Add Id-aware query macros |
Medium | Medium | Low |
Id objects instead of raw values.Id types.Id usage patterns (e.g., "always use ->value() for DB queries").Id parsing failures.Id isn’t JsonSerializable.Id objects with ->value() for debugging.app()->bind() to mock IdGenerator in tests.Id validation failures.null as an ID).Id fields are indexed (e.g., ULID can be indexed as CHAR).Id objects can enforce unique request IDs in queues.Id-based event headers.| Scenario | Impact | Mitigation |
|---|---|---|
| Invalid ID format | 500 errors in API | Add Id::tryFrom() with fallback |
| DB schema mismatch | Query failures | Use migrations with rollback plans |
| Package abandonment | No future updates | Fork or replace with ramsey/uuid |
| Serialization issues | API timeouts | Implement JsonSerializable |
| ID collision | Data corruption | Use `IdGenerator |
How can I help you explore Laravel packages today?