Fix uploads in relationship repeatables #5420
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WHY
BEFORE - What was wrong? What was happening before this PR?
A lot of stuff were broken and there were many issues reported regarding uploaders in relationships. I've been pushing small fixes but never got to the end of the issue because the problem was the implementation as a whole and not only small broken bits.
#5355
#5299
https://stackoverflow.com/questions/77794931/backpack-6-repeatable-with-file-upload-field
AFTER - What is happening after this PR?
The uploaders should properly work on repeatable relationships
HOW
How did you achieve that, in technical terms?
I needed to re-work the whole saving process for repeatable relationships in the uploaders.
In the end we endup with more customized uploaders, tailored each for their needs without having to guess what belongs to where, that was causing most of the issues.
Docs were updated too. Most noticeable change in docs is the mention that "uploaders in relationships should NOT be casted in the models". Laravel-Backpack/docs#537
This is a limitation by the fact that we hook to the "saving" event and if they are casted we can't get the sent files from the entry (only from request), and the request is not reliable due to the nature of how repeatable works.
Is it a breaking change?
No I don't think so.
How can we test the before & after?
Just trying to add a file uploader to any relationship will be enough to get into a broken scenario.