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

Jms Serializer Bidirectional Relation Laravel Package

coosos/jms-serializer-bidirectional-relation

Adds JMS Serializer subscribers that embed a _mapping_bidirectional_relation in serialized data so bidirectional associations can be restored on deserialize. Supports Symfony or standalone setup via event subscribers, with annotations to enable mapping on root models and exclude fields.

View on GitHub
Deep Wiki
Context7

JMS Serializer Bidirectional Relation

Description

Build a mapping for restore bidirectional relation when deserialize process.

This mapping is add to your serialized content with _mapping_bidirectional_relation key.

Install

With jms/serializer (without symfony)

use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\EventDispatcher\EventDispatcher;
use Coosos\BidirectionalRelation\EventSubscriber\MapDeserializerSubscriber;
use Coosos\BidirectionalRelation\EventSubscriber\MapSerializerSubscriber;

$builder = SerializerBuilder::create();
$builder->configureListeners(function (EventDispatcher $dispatcher) {
    $dispatcher->addSubscriber(new MapSerializerSubscriber());
    $dispatcher->addSubscriber(new MapDeserializerSubscriber());
});

$serializer = $builder->build();

With Symfony

# services.yml
Coosos\BidirectionalRelation\EventSubscriber\MapDeserializerSubscriber:
      tags:
        - { name: jms_serializer.event_subscriber }

Coosos\BidirectionalRelation\EventSubscriber\MapSerializerSubscriber:
      tags:
        - { name: jms_serializer.event_subscriber }

Usage

Annotation (Minimum required)

For to avoid mapping on an object that does not need it, you should add @Coosos\BidirectionalRelation\Annotations\SerializerBidirectionalRelation to annotation class (only root model)

Exclude from mapping

If you want to exclude an object to map, you can by adding @Coosos\BidirectionalRelation\Annotations\ExcludeFromMapping annotation to your field.

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.
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo