PHPackages                             gaspertrix/laravel-duplicate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. gaspertrix/laravel-duplicate

ActiveLibrary[Database &amp; ORM](/categories/database)

gaspertrix/laravel-duplicate
============================

Duplicate any Eloquent model along with its underlying relationships

5.0.0(2y ago)0115MITPHPPHP ^7.2

Since Dec 28Pushed 2y agoCompare

[ Source](https://github.com/Gaspertrix/laravel-duplicate)[ Packagist](https://packagist.org/packages/gaspertrix/laravel-duplicate)[ RSS](/packages/gaspertrix-laravel-duplicate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (8)Used By (0)

Duplicate any Eloquent model along with its relationships
=========================================================

[](#duplicate-any-eloquent-model-along-with-its-relationships)

[![Build Status](https://camo.githubusercontent.com/756ba3c7e361dd82d0897ff7d62727e36dbe76546cdf9289be88b0a1d3633da5/68747470733a2f2f7472617669732d63692e6f72672f4e6575726f6e792f6c61726176656c2d6475706c69636174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Neurony/laravel-duplicate)[![StyleCI](https://camo.githubusercontent.com/a735d511f62d0527edc497bf6def715eb2a52189b8bda90c75a780614fedf2c2/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136333334353333392f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/163345339)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9e48a9f23752b78d64fd47d008ad5c83851fe644001514c3ed4313792e1c5987/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e6575726f6e792f6c61726176656c2d6475706c69636174652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Neurony/laravel-duplicate/?branch=master)

- [Overview](#overview)
- [Installation](#installation)
- [Usage](#usage)
- [Customisations](#customisations)
- [Events](#events)

Overview
========

[](#overview)

This package allows you to duplicate any Eloquent model record along with its underlying relationships.

Relationship types that can and will make sense to be duplicated: `hasOne`, `morphOne`, `hasMany`, `morphMany`, `belongsToMany`, `morphToMany`

Installation
============

[](#installation)

Install the package via Composer:

```
composer require neurony/laravel-duplicate

```

Usage
=====

[](#usage)

### Step 1

[](#step-1)

Your Eloquent models should use the `Neurony\Duplicate\Traits\HasDuplicates` trait and the `Neurony\Duplicate\Options\DuplicateOptions` class.

The trait contains an abstract method `getDuplicateOptions()` that you must implement yourself.

Here's an example of how to implement the trait:

```
