Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Hydrator Laravel Package

nutgram/hydrator

nutgram/hydrator is a lightweight PHP library for turning arrays into typed objects, with support for nested DTOs, type casting, and attribute-driven mapping. It integrates smoothly with Nutgram and Laravel-style workflows, reducing boilerplate when working with API payloads and Telegram updates.

View on GitHub
Deep Wiki
Context7

A turbocharged json object hydrator for your DTOs

Frequently asked questions about Hydrator
What is nutgram/hydrator and what does it do?
nutgram/hydrator is a lightweight PHP library that turns arrays and decoded JSON payloads into typed objects, typically DTOs. It supports nested DTOs, type casting, and attribute-driven property mapping, which removes a lot of hand-written array-to-object boilerplate. It is framework-agnostic but integrates smoothly with Nutgram and Laravel-style workflows. It is a mapping utility, not a validation, authorization, or persistence layer.
How do I install nutgram/hydrator in a Laravel project?
Install it with Composer, for example composer require nutgram/hydrator, and commit your lockfile so the resolved version is pinned. Because the package is framework-agnostic, no service provider or published config is normally required unless the README says otherwise. After installing, define a small DTO, hydrate it from a decoded JSON array, and assert the result in a test before using it in real endpoints.
Does nutgram/hydrator need a Laravel service provider or configuration file?
Based on its framework-agnostic design, it should work as a plain Composer dependency without a service provider. Check the repository documentation to confirm whether any optional configuration or attributes need registering. Even if none is required, wrapping calls in your own small hydrator service or interface keeps the dependency centralized and easy to swap later.
Can nutgram/hydrator handle nested DTOs and arrays of DTOs?
Nested DTO support and type casting are part of the package's stated feature set, so mapping an object property to another DTO class should work. Support for collections or arrays of DTOs, backed enums, readonly classes, and nullable or union types is less certain and should be verified with a spike. Write tests against your real payload shapes, especially lists and deeply nested objects, before relying on it broadly.
Which PHP and Laravel versions does nutgram/hydrator support?
The package is framework-agnostic, so Laravel compatibility mostly depends on the PHP version constraint in its composer.json. Confirm the supported PHP range against your application matrix before adoption, since the library may target modern PHP features such as typed properties or attributes. Also verify the release tags are real and inspectable, because the project's metadata should be reviewed as part of your dependency audit.
Does nutgram/hydrator validate data or only hydrate it?
A hydrator maps data into objects; it does not replace validation, authorization, or business rule checks. In Laravel, keep form requests or the Validator as the source of truth and run hydration only after the payload has passed validation. Treat any type coercion the library performs as convenience, not as a guarantee that the input was semantically valid.
How does nutgram/hydrator handle missing, extra, or malformed JSON fields?
The exact behavior for missing keys, unexpected keys, nulls, and type mismatches is not clearly documented, so test each case explicitly. Silent coercion or permissive hydration would be a correctness risk at API boundaries, particularly for nullable and numeric fields. Add automated tests for malformed, partial, and extra-field payloads, and decide whether failures should throw or fall back to defaults.
Is nutgram/hydrator fast enough for production use?
It is described as a turbocharged, lightweight hydrator, but performance depends on how much reflection it does per hydration and whether metadata is cached. Benchmark it with representative payloads from your own endpoints and queue consumers rather than relying on general claims. If reflection caching is not built in, keep DTOs simple and consider caching or memoizing your own mapping layer.
Is nutgram/hydrator safe to adopt given its low adoption and small community?
Adoption is very low, the repository provenance should be verified, and some release metadata looks unusual, so a production recommendation requires code review first. Pin the exact version, audit the dependency, and keep a fork path open under its MIT license. Isolate usage behind an internal interface so you can replace the package without touching domain code.
What are the alternatives to nutgram/hydrator for DTO hydration in Laravel?
Common alternatives include hand-written factory or mapper methods, spatie/laravel-data, and general-purpose serializers such as symfony/serializer or cweiske/jsonmapper. Manual mapping is the most predictable option and has no dependency risk, while laravel-data offers richer validation and casting features at the cost of more magic. Compare candidates on error semantics, nested and enum support, and performance using your own payloads before choosing.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console