if details is json then just cast as an array
protected $casts = [
'details' => 'array'
];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In my Order model I am using:
protected $casts = [
'details' => AsArrayObject::class
];
The field is set up in the migration as:
$table->json('details')->nullable();
When I come to writing to this field I get the following:
"Indirect modification of overloaded property App\Models\Order::$details has no effect"
Very simple way of triggering this is:
$order = new Order();
$order->details['somedata'] = 'somevalue;
$order->save();
I've possibly misunderstood how AsArrayObject is to be used! Taylors original pull request at https://github.com/laravel/framework/pull/36245 and a post at https://www.amitmerchant.com/mutation-free-json-columns-updation-using-asarrayobject-eloquent-cast/ led me to wanting to use AsArrayObject
What am I missing?
Please or to participate in this conversation.