我想從現有雄辯模型及其所有關係中創建一個克隆,而不使用循環關係,因爲我可能會在將來擴展關係。現在我有一個訂單模式:如何克隆laravel中具有所有關係的雄辯對象5.2
$table->bigIncrements('id');
$table->unsignedBigInteger('customer_id');
$table->timestamps();
和秩序有很多項目:
$table->bigIncrements('id');
$table->unsignedBigInteger('order_id');
$table->unsignedInteger('quantity');
還有另一種關係「sell_orders:
$table->bigIncrements('id');
$table->unsignedBigInteger('order_id');
,但我知道它應該是超過這些在未來。我怎樣才能從一個訂單和所有的關係克隆?我發現這個代碼:
$order = Order::find(1);
$clone = $order->replicate();
$clone->push();
$clone->save();
這使得一個新的模型沒有任何關係。