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

Object Mapper Laravel Package

symfony/object-mapper

Symfony Object Mapper component maps data from one object to another using PHP attributes. Simplifies DTO/entity transformations, supports configurable mapping rules, and integrates with the Symfony ecosystem. Documentation and contributions are handled in the main Symfony repository.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • DTO/DTO Pattern Adoption: Accelerates implementation of Data Transfer Objects for API layers, reducing manual property mapping in controllers or services. Example: Automatically convert UserEntity to UserResponseDTO with zero boilerplate.
  • API Layer Modernization: Enables clean separation between domain models and API contracts, critical for microservices or headless architectures. Aligns with roadmaps to decouple business logic from presentation layers.
  • Build vs. Buy: Justifies leveraging open-source over custom solutions for teams already using Symfony components (e.g., HTTPFoundation, Messenger) or PHP 8+. Avoids reinventing mapping logic for nested objects, collections, or type conversions.
  • Use Cases:
    • Laravel API Development: Replace manual array_map or create() chains in controllers with attribute-driven mapping (e.g., @MapEntity, @Ignore).
    • Legacy System Integration: Bridge gaps between outdated database schemas and modern Laravel models (e.g., mapping legacy User tables to UserProfile DTOs).
    • Testing: Dynamically generate test data by mapping between fixtures and application objects (e.g., UserFactoryUser).
    • Event-Driven Architectures: Map between domain events and command/query objects (e.g., OrderCreatedEventOrderCommand).

When to Consider This Package

  • Adopt if:

    • Your Laravel app uses Symfony components (e.g., HTTPFoundation, UX, Messenger) or targets PHP 8.1+ for attribute support.
    • You frequently handle complex object transformations (e.g., nested DTOs, collections, or type conversions like stringCarbon).
    • Your team prioritizes developer velocity over micro-optimizations (e.g., avoiding manual setName() chains in controllers).
    • You need declarative mapping rules via PHP attributes (e.g., @MapEntity, @Ignore) to reduce boilerplate.
    • Your roadmap includes microservices, API Platform, or domain-driven design (DDD) where object mapping is critical.
  • Look elsewhere if:

    • Your project is simple CRUD with no DTOs or complex mappings (overkill for basic Model::find()json_encode()).
    • You require high-performance mapping (benchmark against alternatives like Mapperly or JMS Serializer).
    • You’re not using PHP 8+ (attributes are required for full functionality).
    • You prefer Laravel-native solutions like spatie/laravel-data or php-http/message for tighter integration.
    • Your objects have dynamic or runtime-defined structures (e.g., JSON Schema-based APIs; consider symfony/serializer instead).

How to Pitch It (Stakeholders)

For Executives: "This package slashes API development time by automating the tedious task of manually mapping between database records, internal objects, and API responses. For example, converting a UserEntity to a UserResponseDTO—which today requires 20+ lines of boilerplate—could be done in 2 lines with attributes like @MapEntity. This directly supports our goals to [reduce tech debt/accelerate feature delivery] while keeping code clean and maintainable. It’s a low-risk choice, backed by Symfony’s stability, and MIT-licensed for full flexibility. The ROI comes from faster iterations and reduced bugs in our API layer."

For Engineers: "Symfony’s Object Mapper lets us replace repetitive mapping logic with declarative attributes (e.g., @MapEntity, @Ignore), cutting cognitive load and runtime errors. It integrates well with Laravel’s DI system (via symfony/dependency-injection) and supports nested objects/collections out of the box. For teams using Symfony components or PHP 8+, this is a no-brainer—it’s battle-tested, actively maintained, and avoids reinventing the wheel. If we’re not using Symfony, we could evaluate alternatives like spatie/laravel-data, but this gives us the most ‘batteries-included’ experience for complex mappings. It’s especially useful for APIs, DDD, or legacy integrations where object transformation is a pain point."

For Architects: *"This package aligns with clean architecture principles by enforcing separation between domain models and API contracts. It’s particularly valuable for:

  • Microservices: Decoupling services with standardized mapping rules.
  • Legacy Modernization: Bridging outdated schemas to modern Laravel models.
  • Event-Driven Systems: Mapping between domain events and commands/queries. The trade-off is minor learning curve (PHP attributes) for major productivity gains. For Laravel apps already using Symfony components, the integration is seamless; otherwise, we’d need to evaluate the effort to bind it via the service container."*
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai