bornfight/transfer-object-converter
spatie/laravel-data).Illuminate\Http\Request but does not integrate natively with Laravel’s validation pipeline (e.g., validate() or authorized()). May require custom middleware or service layer logic.Request class, this package does not validate data—it only hydrates objects. Validation must be handled separately (e.g., via Laravel’s Validator or a library like respect/validation).Illuminate\Support\Data in Laravel 10+), making this package redundant for basic use cases.Request or Data classes lack?spatie/laravel-data, mattstauffer/arrayable) that are actively maintained?json_decode()?Request class) suffices.spatie/laravel-data, php-ddd).Request::all(), json_decode()).CreateUserRequest, UpdateProfilePayload).TransferObjectConverter.Illuminate\Support\Data.symfony/serializer).AppServiceProvider:
$this->app->bind(TransferObjectConverter::class, function ($app) {
return new TransferObjectConverter();
});
public function handle(Request $request, Closure $next) {
$dto = $this->converter->convert($request->json()->all(), NewRequestDto::class);
$request->merge(['dto' => $dto]);
return $next($request);
}
$validated = $request->validate([...]);
With:
$dto = $this->converter->convert($request->json()->all(), NewRequestDto::class);
$validator = Validator::make($dto->toArray(), [...]);
TransferObjectConverter.json_decode() + array_map.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Malformed JSON input | Uncaught exceptions or partial DTOs | Add try-catch blocks; validate JSON first. |
| Missing required DTO properties | Incomplete objects | Combine with Laravel’s validate() or respect/validation. |
| PHP 8.x incompatibility | Runtime errors | Fork and update; or replace with modern alternative. |
| Reflection security warnings | Deprecation notices | Suppress warnings or refactor to avoid reflection. |
| Dependency conflicts | Package installation fails | Use composer.json overrides or aliases. |
How can I help you explore Laravel packages today?