Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Smiffy's avatar

"Indirect modification of overloaded property" issue with AsArrayObject

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?

0 likes
3 replies
automica's avatar

if details is json then just cast as an array

protected $casts = [
    'details' => 'array'
];
Smiffy's avatar

I would have to rework my code to:

$details = [
    'somedata' => 'somevalue
];

$order->details = $details;

Which works. But the point of AsArrayObject AFAIK is that I should be able to set the json field directly

Please or to participate in this conversation.