Closed osteel closed 4 years ago
Yeah, I definitely need to improve this - plan for next version is only to use the validated data for filling, which would mean if you didn't validate the relationships on the update request they wouldn't be filled.
In the meantime overload the getFillable()
method on your adapter. It receives the model that is being filled so you can check $model->exists()
to decide what list of fillable JSON API fields you should return. That's how we do it!
@lindyhopchris awesome, I'll give that a try on Monday and close the issue if that solves it (which I'm sure it will).
Thanks for your work and reactivity, it's very much appreciated.
All good! 👍
Hi,
Apologies if that's been asked before but I can't seem to find a similar issue on Github nor the answer in the documentation.
I've got a
Comment
resource which has aPost
relationship.Post
must be specified atComment
creation (hence it is present in the adapter's$fillable
array), but shouldn't be modifiable when the comment is subsequently updated.This is the validators'
rules
method for theComment
resource:Unfortunately, not setting a rule for
post
at update doesn't prevent the relationship from being updated.I also overwrote the
dataForUpdate
method to strip the relationships altogether:Relationships are correctly removed from
$document
, yet the post is still updated.A couple of questions:
Thanks in advance!