Two fieldsets for the same relationship on two wizard steps not working
I have a wizard that saves some data on
User
, and some data on Profile
which belongs to a user.
The fields that are related to Profile
are put on two different steps of a Wizard
inside a Fieldset
with relationship
method pointing to the HasOne
profile relationship on user model.
It works fine if I only have one fieldset linked to this relationship, but breaks when I have two.
Any ideas how I can fix this collision?8 Replies
Do they have the same name?
No, they are on the same relationship, but I've used different names in the
make
method.It could be when saving the relationships the name is the same given you wouldn't expect them to naturally be different so it's overwriting it.
Clone the relationship with a new name and try that.
Ok, update, this only happens with
SpatieMediaLibraryFileUpload
component. Normal fields work fine.
It doesn't seem related to relationship name.
Cloning the relationship actually works, but this is a nasty hacky fix. Any way we can avoid that? Should I open an issue?https://github.com/filamentphp/filament/issues/12401
opened an issue
GitHub
Can't have medialibrary fields in two fieldsets for the same relati...
Package filament/spatie-laravel-media-library-plugin Package Version v3.2.70 Laravel Version v11.4.0 Livewire Version No response PHP Version 8.3.6 Problem description I have a wizard that saves so...
Why is it nasty? It could be said it's nasty to use one relationship for multiple data sources.
You could just extend the original relationship so it's essentially just namespacing it.
I think it's nasty because I will have an unnecessary duplication in my model code, which is only there because of a presentation layer decision to separate the form into multiple wizard steps.
Otherwise I would never create two identical relationships with different names.
One sign of this smell is the fact that I have to write a comment above one of the relationship methods to avoid any confusion why we have two methods for the same relationship.
And you can't easily test this, so if someone confident comes in the future and deletes the method, they won't know that they have broken the app. They will just think I was stupid to have such duplication in my code.
Does this make sense?
So just do return the previous relationship.... it's a weird scenario to use 1 relationship for multiple use cases.