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

Mapper Laravel Package

tadcka/mapper

A Laravel package for mapping data between arrays, objects, and models, helping keep transformation logic clean and reusable. Useful for converting API payloads, DTOs, and Eloquent attributes without scattering manual assignment code across your application.

Deep Wiki
Context7

Mapper component.

Frequently asked questions about Mapper
How do I install tadcka/mapper in a Laravel application?
Install it with Composer using composer require tadcka/mapper. The package ships a Laravel service provider that is registered automatically through package discovery on modern Laravel versions. If you are on an older Laravel release without auto-discovery, add the service provider to the providers array in config/app.php manually.
Does tadcka/mapper work outside of Laravel in plain PHP?
Yes. The package is described as a lightweight data mapping library for PHP and Laravel, so the core mapping logic does not require the framework. The Laravel service provider exists only to wire the mapper into the container and configuration. You can therefore use it in standalone PHP projects or non-Laravel frameworks.
Should I define mappings with attributes or with configuration?
Both approaches are supported, so the choice depends on your codebase style. Attributes keep the mapping definition next to the DTO properties, which is convenient for small, self-contained classes. Configuration-based mappings keep DTOs free of package-specific annotations, which can be preferable when your objects are shared with other libraries.
How does tadcka/mapper handle nested objects and collections?
The mapper supports nested structures, so a property can be mapped to another typed object rather than a raw array. Collections of nested items are handled as well, letting you hydrate arrays of DTOs from a list in the source data. You define the target type in the mapping and the mapper resolves it recursively.
Does the mapper cast values to the correct property types?
Yes, type casting is part of the hydration process, so values from arrays or source objects are converted to match the target property type. Hydration is also null-safe, meaning missing or null source values do not cause unexpected assignment errors. This reduces the manual casting and isset checks you would otherwise write by hand.
Can I use tadcka/mapper to convert API payloads into DTOs?
That is one of the primary use cases. You can map a decoded JSON array from an API response directly into a typed DTO, including nested objects and collections. This keeps transformation logic in one reusable place instead of scattering manual array assignments across controllers and services.
How do I extend tadcka/mapper with a custom mapper or transformer?
The package is designed to be extensible through custom mappers and transformers. You implement handling for the type or conversion the built-in behaviour does not cover and register it with the mapper. This lets you support value objects, custom formats, or third-party types without forking the package.
Which PHP and Laravel versions does tadcka/mapper support?
The package targets PHP and Laravel, but the exact version constraints are declared in its composer.json. Check the require section there before adding it to an existing project, especially if you are on an older Laravel release. Pinning a compatible version in your composer.json is the safest way to avoid surprises during upgrades.
How do I unit test code that uses tadcka/mapper?
Because mapping definitions live on plain PHP classes, you can instantiate the mapper in a normal PHPUnit or Pest test without booting a full Laravel application. Map a sample array or object and assert the resulting DTO properties, including nested objects and collections. For Laravel-specific integration, add feature tests that resolve the mapper from the container.
Is tadcka/mapper a good alternative to manual hydration or a full serializer?
It is a focused, lightweight option when you mainly need array-to-object and object-to-object mapping with typed properties. Compared to hand-written hydration code, it removes repetitive assignment and casting logic and keeps definitions reusable. If you need advanced serialization features such as complex normalization groups or format negotiation, a full serializer may still be a better fit.
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.
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
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource