I'm using voyager admin panel for my website. I have more than 3000 products.
How Can I add duplicate/clone a product button in voyager admin panel?
My Answer:
To add a duplicate/clone product button in Voyager Admin Laravel, you can follow these steps:
1. Create a new route in your `web.php` file:
php
Route::get('products/{id}/duplicate', 'ProductController@duplicate')->name('products.duplicate');
2. Create a new method in your `ProductController`:
php
public function duplicate($id)
{
$product = Product::findOrFail($id);
$newProduct = $product->replicate();
$newProduct->name = $product->name . ' (Copy)';
$newProduct->save();
return redirect()->route('voyager.products.index')->with('success', 'Product duplicated successfully');
}
3. Add a new button in your `products` BREAD view in Voyager:
php
{
'title' => 'Duplicate',
'icon' => 'voyager-params',
'class' => 'btn btn-sm btn-primary',
'route' => 'products.duplicate',
'parameters' => [$data->id]
}
4. Make sure to replace `Product` with your actual product model and adjust the route and button parameters as needed.
With these steps, you should now have a duplicate/clone product button in your Voyager Admin panel that allows you to easily duplicate products.
Rate this post
4 of 5 based on 3962 votesComments