drjele/doctrine-type
Laravel package to add custom Doctrine DBAL types and mappings, improving schema introspection and migrations for non-standard database column types. Helps register and use bespoke types cleanly across your application.
drjele/doctrine-type package provides custom Doctrine DBAL types, enabling support for non-standard data types (e.g., JSON, UUID, enums, or custom serializable objects) in PHP applications using Doctrine ORM/DBAL. This is particularly valuable for:
json, uuid, and enum columns) may reduce urgency for this package unless custom types are needed.Platform or Type abstractions, but may require manual binding to Eloquent’s schema builder.Doctrine\DBAL\Types\Type::addType()), simplifying schema changes.Doctrine\DBAL\Types\Type correctly.Platform classes) could lead to breakage if Laravel’s Doctrine integration evolves.json column for JSON data).Why Custom Types?
json, uuid) insufficient? What specific use cases justify this package?Geohash type for spatial queries not supported by Laravel’s built-in types."Integration Depth
json column vs. custom JsonType)?Performance
Platform optimizations (e.g., PostgreSQLPlatform for JSONB)?Long-Term Viability
Attribute system or custom accessors?Testing Strategy
addType() in a service provider).text columns with typed Json columns).JsonType) in a Laravel service provider:
use Doctrine\DBAL\Types\Type;
use drjele\DoctrineType\JsonType;
if (!Type::hasType('json_custom')) {
Type::addType('json_custom', JsonType::class);
}
Schema::create('posts', function (Blueprint $table) {
$table->jsonCustom('metadata'); // Hypothetical custom column
});
json column with custom accessors.^2.5 or ^3.0).JSONB vs. JSON).$casts property.where clauses, joins, and aggregations.Post::where('metadata->path', 'key', 'value')->get();drjele/doctrine-type package or Doctrine DBAL.composer.json to avoid surprises.\Log::debug('Custom type conversion', ['data' => $rawData, 'converted' => $convertedData]);
GeohashType throws an error, ensure the database column uses CHAR(11)."| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Type registration fails | Custom types unavailable | Validate Type::hasType() in service provider. |
| Database schema mismatch | SQL errors on migration | Use doctrine/dbal migrations for safety. |
| Serialization corruption | Data loss or invalid queries | Add validation in model observers. |
| Doctrine version |
How can I help you explore Laravel packages today?