mathieutu / laravel-json-syncer

A Json importer and exporter for Laravel.
MIT License
28 stars 7 forks source link

Will this work with polymorphic relationships #8

Closed nikocraft closed 4 years ago

nikocraft commented 5 years ago

Hi Mathieu, can your package export relatioships that are polymorphic in nature?

mathieutu commented 5 years ago

For now it can handle only HasOneOrMany relationship, as other ones ask for more complex information that cannot be just in the json, and are not based on a standard json tree.

For Polymorphic, actually we could do something for MorphOne and MorphMany as they are HasOneOrMany relations.

Something clean to do would be to modify the code to use the internal methods of laravel instead of setting manually relations attributes.

I'm not using the package right now, so if you want to do it, I'd be glad to help you if needed, and accept a PR.

Matt'

mathieutu commented 5 years ago

After looking again at the code, I think that you actually should try for MorphOne and MorphMany relations. If the type is exported, it could import it as well, and it will works!

Let me know.

nikocraft commented 5 years ago

@mathieutu will it work with morphToMany?

public function settings()
{
    return $this->morphToMany(Setting::class, 'settingable');
}
mathieutu commented 4 years ago

Closing due to inactivity. I let you try and let us know if you found your answers.