create(); // $this->duplicate(); } /** * @throws \Throwable */ private function duplicate(): void { $baseProduct = Product::with(['productCategories', 'descriptions', 'skus'])->findOrFail(2); $newProduct = $baseProduct->replicate(); $newProduct->saveOrFail(); $newProductId = $newProduct->id; if ($newProductId) { $relations = $baseProduct->getRelations(); foreach ($relations as $name => $relation) { dump($name); foreach ($relation as $relationRecord) { $newRelationship = $relationRecord->replicate(); $newRelationship->product_id = $newProductId; $newRelationship->push(); } } } } }