Hi Dev’s, Today in this I will show you Copy Record using Eloquent Replicate in laravel. Now, let’s start a new article of laravel copy row by using replicate in laravel. Now in this article, i will implement a laravel duplicate record. So I hope this example will help you on laravel eloquent copy record example. Now you can learn Laravel Copy Record using Eloquent.
Sometime we have to create more duplicate record on same database table. At that time if we want to create that all record manually then it will take long time and also can generate error. as specially issue when we need to 10 or 20 fields on one table. So on laravel eloquent provide us replicate() function that can help us to create duplicate entry on same database table.
Also we can easily use replicate() function with laravel 8 version application.
Let’s start and see two very simple example of how to create duplicate record by using replicate().
Example 1 :
<?php namespace App\Http\Controllers; use App\Models\Product; class SignaturePadController extends Controller { /** * Write code on Method * * @return response() */ public function index() { $product = Product::find(2); $newProduct = $product->replicate()->save(); dd($newProduct); } }

Example 2: Update Some Fields
<?php
namespace App\Http\Controllers;
use App\Models\Product;
class SignaturePadController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$product = Product::find(2);
$newProduct = $product->replicate();
$newProduct->amount = 100;
$newProduct->save();
dd($newProduct);
}
}

Read Also : proc_open(): fork failed – Cannot allocate memory laravel in ubuntu
Thanks for read. I hope it help you. For more you can follow us on facebook