approval icon indicating copy to clipboard operation
approval copied to clipboard

Issue creating an approval when it has a field cast as "array" type

Open anchovie91471 opened this issue 5 months ago • 2 comments

I have a model with a field that stores data in a JSON db column. I am casting that data as "array" on the model.

protected $casts = [ 'types' => 'array', ];

When creating a new approval on the model, the data from that field is escaped before it's written to the approval table. When approving the model with:

Approval::where('id', 1)->approve();

The escaped data is written to the intended model's table but isn't cast as an array by Laravel because of the extra characters on the string.

I think what's needed is at line 32 in MustBeApproved.php.

change: if (isset($model->casts[$key]) && $model->casts[$key] === 'json') {

to if (isset($model->casts[$key]) && ($model->casts[$key] === 'json' || $model->casts[$key] === 'array')) {

I made the above change, created a new model, that saved an approval, and then approved the model. It works. I'm happy to submit a PR for the change if needed.

anchovie91471 avatar Sep 04 '24 21:09 anchovie91471