Error reported in Laravel 9: Indirect modification of overloaded property returnorder::$order has no effect
1. Report an error in Laravel 9: Indirect modification of overloaded property returnRorder::$order has no effect. as shown in Figure 1
{
"status_code": 500,
"code": 0,
"message": "Indirect modification of overloaded property ReturnOrder::$order has no effect",
"trace": {
"line": 648,
"file": "E:\\object\\ReturnOrderService.php",
"class": "ErrorException"
}
}
2. The code is implemented as follows
$item->order = $keyedOrders[$item->order_id] ?? null;
$item->order->returnOrders = $keyedOrderReturnOrders[$item->order_id] ?? new EloquentCollection();
2. The adjusted code is implemented as follows, no more errors are reported
$item->order = $keyedOrders[$item->order_id] ?? null;
if ($item->order) {
$item->order->returnOrders = $keyedOrderReturnOrders[$item->order_id] ?? new EloquentCollection();
}
