0
我試圖複製行但沒有結果,我得到的訂單複製沒有相應的項目。Laravel 4.2複製包括子項目
ORDERS pk(id) auto increment
id total status date
-----+-------------+-----------+-------------
118 899.58 2 2015-03-03 00:18:58
119 38.55 2 2015-03-03 00:18:58
ITEMS pk(order_id,product_id) corresponding items childs:
order_id product_id quantity
----------+-------------+----------
118 1115 82
119 8965 12 /// ro replicate
$idnew = Order::find($idorder)->replicate()->save(); // create new OK
$idnewId = $idnew->id;/////obtain id of last insert
$itemstemp = DB::table('item')->where('order_id', '=' ,$idnewId)->get();
foreach($itemstemp as $itemte){
DB::table('item')->insert(array(
'order_id' => $itemte->order_id,
'product_id' => $itemte->product_id,
'quantity' => $itemte->quantity
));
}
響應ErrorExceptionTrying得到非對象 線$ idnewId = $ idnew-> ID的屬性;
所需的輸出:
ORDERS pk(id)
id total status date
-----+-------------+-----------+-------------
118 899.58 2 2015-03-03 00:18:58
119 38.55 2 2015-03-03 00:18:58
120 38.55 2 2015-03-03 00:18:58
ITEMS pk(order_id,product_id) corresponding items childs:
order_id product_id quantity
----------+-------------+----------
118 1115 82
119 8965 12
119 2255 22
120 8965 12
120 2255 22
任何想法,請
感謝盧卡,我嘗試並執行查詢沒有錯誤,但沒有插入子項行 – Userlaravel 2015-03-03 13:54:05
你確定嗎?請用我的答案仔細檢查你的代碼。因爲'replicate()'應該肯定會返回一個對象(模型實例要精確) – lukasgeiter 2015-03-03 13:55:59
是的,對不起。我改了一個錯誤拼寫錯誤的變量。現在執行查詢沒有錯誤,但沒有插入子項行 – Userlaravel 2015-03-03 14:00:58