I have the following Eloquent request:
$item = Item::where('sku', $sku)->first();
After this request, I add several items manually, for example:
$item['total'] = $item['subtotal'] + $this->currentInventory();
Statements like the ones above that change the facility very well.
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 to $item['fields'][$f->field_group_name] = [];throw an 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 the actual element to the array $item['fields']that I get this error?
PHP version 5.6.0.
source
share