Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.04k stars 885 forks source link

Fix uploads in relationship repeatables #5420

Closed pxpm closed 7 months ago

pxpm commented 7 months ago

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.

https://github.com/Laravel-Backpack/CRUD/issues/5355 https://github.com/Laravel-Backpack/CRUD/issues/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". https://github.com/Laravel-Backpack/docs/pull/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.