행을 복제하려고했지만 결과가 없으면 해당 항목없이 주문이 복제됩니다.
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
));
}
응답 ErrorException 개체가 아닌 줄의 속성을 가져 오는 중입니다. $ 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
어떤 아이디어라도주세요
save()
저장이 작동하는지 여부 만 부울을 반환합니다. 대신해야 할 일은 다음과 같습니다.
$new = Order::find($idorder)->replicate();
$new->save();
$itemstemp = DB::table('item')->where('order_id', '=' ,$new->id)->get();
// and so on...
또한 나는 당신의 논리가 약간 잘못되었다고 생각합니다. 그런 것이 나에게 더 의미가 있습니다.
$new = Order::find($idorder)->replicate();
$new->save();
$items = DB::table('item')->where('order_id', $idorder)->get();
$newItems = [];
foreach($items as $item){
$newItems[] = [
'order_id' => $new->id,
'product_id' => $item->product_id,
'quantity' => $item->quantity
];
}
DB::table('item')->insert($newItems);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다