-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[6.x] No mass update of json field ['json_field->json_attr' => 'new value'] even if json_field is not guarded #33975
Comments
for now i'm overriding isGuardableColumn() in models class where i need control of $garded with: class MyModel extends Model
{
...
/**
* Override Illuminate\Database\Eloquent\Concerns\GuardsAttributes trait function
*
* @param string $key
*
* @return bool
*/
protected function isGuardableColumn($key)
{
return true;
}
...
} It's not the best, because is not a patch or a solution, it's only a workaround to disable fix without downgrade version |
This isn't possible anymore with the recent security update. See https://blog.laravel.com/security-release-laravel-61835-7240 |
@driesvints excuse me but you are saying that in model class is not possible update single key of json column even if is not guarded? I'm a bit confused. To do it i must use DB::update()? |
Have you read the blog post? We don't support mass assignment through JSON this way. Try adding the column to your |
Hi @driesvints yes i read post, but even if json column is fillable i can't update It seems i've two options only:
I can't do option 2 because my json column have dynamic keys. I thought that fix should avoid update of json keys if json column is guarded and not avoid json key mass update, thanks for your reply. |
Description:
Update specific keys of a json field using mass assignment doesn't work even if column is not in $guarded.
Adding json colum to $fillable doesn't work too.
I think the problem is due to
framework/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php
Lines 193 to 202 in bf73487
that it search
json_field->json_key
in table column names list even if $key is not in $garded.I use json field to store dinamic data and i don't know all json keys, so i can't add the json_field->json_key to $fillable variable.
Steps To Reproduce:
protected $guarded = ['id'];
desciption is updated but json_field->json_key isn't updated
The text was updated successfully, but these errors were encountered: