ICStudio
Services
PortfolioCase Studies
Tools
DemoBlog
ICStudio
HomeBlogDuplicate entities in October CMS

Duplicate entities in October CMS

When creating content in OctoberCMS, it is often necessary to copy (clone) some Model. Or to put it simply in the language of your customers: How do I copy an existing record? Given the frequency of requests for this functionality, I want to give the idea to generate this block of code by default in Rainlab.Builder 😎

Published: 10/25/2021

When creating content in OctoberCMS, it is often necessary to copy (clone) some Model.
Or to put it simply in the language of your customers: How do I copy an existing record? Given the frequency of requests for this functionality, I want to give the idea to generate this block of code by default in Rainlab.Builder 😎

First, find the necessary controller of your plugin, for example plugins/icstudio/control/controllers/Tariffs.php

Now let's add a new method to it that will create copies of the required Mods. On the Internet you can find similar code, but we have finalized it, so it is not recommended to use copied.
- number 2 will be added to the record name;
- number 2 will be added to slug;
- the is_active key will be set to 0. This will keep your production from outputting wrong data.


public function onDuplicate()
{
$checked_items_ids = input('checked');
foreach ($checked_items_ids as $id) {
$original = TariffModel::where("id", $id)->first();
$clone = $original->replicate();
$clone->name = $clone->name . '2';
$clone->slug = $clone->slug . '2';
$clone->service_name = $clone->service_name . '2';
$clone->is_active = 0;
$clone->save();
}
Flash::success('Записи скопированы');
return $this->listRefresh();
}


Now you need to bind this action to the backend layout. For this purpose find file _list_toolbar.htm for your controller, for example for controller from the example the path to this file will be: plugins/icstudio/control/controllers/tariffs/_list_toolbar.htm

Let's add this code to output the button:

class="btn btn-default oc-icon-clone" disabled="disabled" onclick="$(this).data('request-data', { checked: $('.control-list').listWidget('getChecked') })" data-request="onDuplicate" data-request-confirm="Хотите скопировать указанные записи?" data-trigger-action="enable" data-trigger=".control-list input[type=checkbox]" data-trigger-condition="checked" data-request-success="$(this).prop('disabled', true)" data-stripe-load-indicator> Копировать выбранные записи

The code for the button must be inside

...

Save, clear the cache and enjoy:




Share:

Want to work with us?

Let's discuss your project and find the best solution

Contact us

Related Posts

10/16/2024

Why October CMS is the ideal choice for Creative Businesses and Businesses with non-standard business processes

10/14/2024

Online Payment Security: How to Protect Client Data in Your Laravel Project

5/17/2023

Pawnshop software: benefits, features, requirements

ICStudio

Professional web development and IT solutions for business

Quick Links

  • Home
  • Portfolio
  • Case Studies
  • Blog
  • Team

Resources

  • Tools
  • AI Chatbots
  • Demo
  • Docs
  • Pilot Program
  • Hire Us

Services

  • Web Development
  • E-commerce
  • CRM
  • Support

Contacts

  • hello@icstudio.online
  • +38 099 123 45 67
  • Kyiv, Ukraine

© 2026 IC Studio. All rights reserved.

Privacy PolicyTerms of ServiceService Terms