-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating model with a json-casted field and guarded id does not work with terse arrow syntax #40506
Comments
@driesvints Makes sense. Thanks for looking into this. I was following advice from here: https://www.youtube.com/watch?v=wPOCQUDUsVc Planning to move back to $fillable per Taylor's recommendations here: https://blog.laravel.com/security-release-laravel-61835-7240 |
Hey. @fylzero i indeed was wrong. Needs to be fillable: laravel/docs#7606 (comment) |
@driesvints I actually figured that out just before you responded, but thank you. One thing that might be worth noting is that you now need to apparently place the arrow syntax reference in your fillable property like so: Edit: Oop! Nevermind, I see where Taylor pointed to this in the docs. Might be good to link that as a reference here: https://laravel.com/docs/8.x/eloquent-mutators#array-and-json-casting That would seem useful as a note there. |
Thanks for figuring that out. It should definitely go in the docs, as there is already a example, that simple doesn't work. I assumed that I had to add my json field name, but not that I had to add the keys too. |
Submitted a PR |
Description:
When attempting to update a JSON-casted field (not the id field) using the terse/arrow syntax on a model that has
$guarded = ['id']
the intended json field does not change/update.Steps To Reproduce:
$guarded = ['id']
andprotected $casts = ['json_field' => 'json'];
to the model$user->update(['options->key' => 'value']);
Not sure why this is happening specifically when the id field is guarded even when you are not explicitly updating the id column. If you remove that guard, it will update as expected.
https://github.com/fylzero/bug-report - Follow the readme file, view the model and tests
The text was updated successfully, but these errors were encountered: