I have the following Eloquent query:
$item = Item::where('sku', $sku)->first();
After this query comes in I'm adding a variety of elements manually such as:
$item['total'] = $item['subtotal'] + $this->currentInventory();
Statements like the above that modify the object work just fine.
It stops working when I do the following:
$item['fields'] = [];
$fields = DB::table('item_fields')->where('item_id', $item['id'])->get();
foreach ($fields as $f) {
if (!isset($item['fields'][$f->field_group_name]))
$item['fields'][$f->field_group_name] = [];
$item['fields'][$f->field_group_name]['valid_values'] = DB::table('item_field_valid_values')->where('item_field_id', $f->item_field_id);
}
This will cause the line $item['fields'][$f->field_group_name] = [];
to produce the error:
Indirect modification of overloaded element of Item has no effect
How can it be that I can assign $item['fields'] = []
but when I try to add an actual element to the $item['fields']
array that I get this error?
PHP version 5.6.0.