在 Laravel 9 中报错:Indirect modification of overloaded property ReturnOrder::$order has no effect
1、在 Laravel 9 中报错:Indirect modification of overloaded property ReturnOrder::$order has no effect。如图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、代码实现如下
$item->order = $keyedOrders[$item->order_id] ?? null; $item->order->returnOrders = $keyedOrderReturnOrders[$item->order_id] ?? new EloquentCollection();
2、调整后的代码实现如下,不再报错
$item->order = $keyedOrders[$item->order_id] ?? null; if ($item->order) { $item->order->returnOrders = $keyedOrderReturnOrders[$item->order_id] ?? new EloquentCollection(); }
近期评论