Weave Code
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

cmath10/mapper

A lightweight Laravel/PHP mapping utility to transform data between arrays and objects using configurable field mappings. Helps normalize payloads, rename keys, cast values, and build DTO-style structures with minimal boilerplate.

View on GitHub
Deep Wiki
Context7

At a glance

Frequently asked questions about Mapper
How does cmath10/mapper compare to Laravel’s built-in `collect()` or `array_map()` for data transformation?
This package is designed for complex, reusable mappings between arrays and objects, unlike `collect()` or `array_map()`, which are one-off transformations. It enforces configurable field rules (e.g., renaming keys, type casting) and works well for DTOs or API responses, while native methods require manual loops or closures for repetitive tasks.
Can I use cmath10/mapper with Laravel Eloquent models to transform database records into DTOs?
Yes, the package is ideal for Eloquent models. You can define mappings to convert model attributes into DTOs or API responses with custom field names, value casting, or nested object structures. It integrates cleanly with Laravel’s service layer to decouple data access from business logic.
What Laravel versions and PHP versions does cmath10/mapper support?
The package likely targets Laravel 8.1+ and PHP 8.0+ (check the `composer.json` for exact requirements). If your project uses older versions, test thoroughly for compatibility, as reflection-based mapping may behave differently in older PHP versions.
How do I define custom field mappings (e.g., renaming keys, casting values) in cmath10/mapper?
Mappings are typically defined via configuration arrays or classes, specifying source and destination fields, value transformations (e.g., `date: 'Y-m-d'`, `cast: 'int'`), and nested object mappings. The package should support both inline definitions and reusable mapping classes for complex scenarios.
Does cmath10/mapper handle nested arrays or circular references in data?
The package may support nested mappings (e.g., `user.address` → `address` object), but circular references (e.g., self-referential objects) could cause infinite loops unless explicitly handled. Test with your data structure to ensure stability, or use Laravel’s `collect()` as a fallback for edge cases.
Will cmath10/mapper work with Laravel API Resources or Spatie’s `laravel-data` package?
It should integrate well with API Resources by replacing manual `toArray()` logic with configurable mappings. For `laravel-data`, evaluate whether the package’s approach overlaps or complements Spatie’s data transfer objects. Avoid mixing both unless they’re designed to coexist.
How do I handle missing or null values during mapping?
The package likely provides options to ignore missing fields, set defaults, or throw exceptions. Configure this behavior per mapping rule (e.g., `ignore_missing: true` or `default: null`). For strict validation, pair it with Laravel’s Form Requests or custom validation logic.
Is cmath10/mapper suitable for high-performance applications (e.g., bulk API responses)?
Reflection-based mapping can introduce overhead, so benchmark with large datasets (e.g., 1,000+ records). For performance-critical paths, consider caching mappings or using native `collect()` for simple transformations. The package may not be ideal for real-time systems where latency is a concern.
Are there alternatives to cmath10/mapper for Laravel data mapping?
For lightweight needs, use Laravel’s `collect()` or `array_map()`. For complex projects, evaluate Symfony Serializer, Doctrine Hydrator, or Spatie’s `laravel-data`. If you’re already using API Platform or GraphQL (Lighthouse), check their built-in mapping tools to avoid redundancy.
How can I test cmath10/mapper in a Laravel project before full adoption?
Start by mapping a single module (e.g., User or Product) and compare performance/memory usage against manual transformations. Use Laravel’s testing tools to verify edge cases (e.g., null values, nested data). Gradually replace custom `toArray()` methods in models or API Resources with the package’s mappings.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky