Closed carlobeltrame closed 3 years ago
@troelskn Any feedback on this? I actually currently don't need it anymore because my belongsTo
relation has changed to belongsToMany
, but the issue might return in the future or for other users of this package.
I guess this package is not maintained anymore... too bad.
In #19 and #18, support was added for detaching relations by passing an empty array. This works fine for most relation types. However, in the case of
belongsTo
relations, this doesn't work becausefillBelongsToRelation
reacts to an array by searching a related model in the database. An empty array isn't naturally used to represent the absence of a belongsTo relation.I'd like to propose to also interpret
null
as "detach all attached related records":The developer could then still to leave a relation untouched by leaving or filtering it out of the attributes array:
The advantage is that this way, Laravel FormRequests can be used directly (as is the purpose of this library I think):
I have created a PR #27 for this using
Arr::has
instead of a null check. I am aware this is a small breaking change. If requested, I could also do an alternate implementation that only accepts this type of detaching forbelongsTo
relations. But that might involve some refactoring in thefill
method in order to reduce code duplication.