PHPackages                             vildanbina/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. vildanbina/laravel-duplicate

ActiveLibrary

vildanbina/laravel-duplicate
============================

Duplicate any Eloquent model along with its underlying relationships

064PHP

Since Dec 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/vildanbina/laravel-duplicate)[ Packagist](https://packagist.org/packages/vildanbina/laravel-duplicate)[ RSS](/packages/vildanbina-laravel-duplicate/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)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/68d664e3fb1eb5dfe74bd814f80ed6bb392ce0e030c28edbbe841b04efe19939/68747470733a2f2f7472617669732d63692e6f72672f76696c64616e62696e612f6c61726176656c2d6475706c69636174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vildanbina/laravel-duplicate)[![StyleCI](https://camo.githubusercontent.com/a735d511f62d0527edc497bf6def715eb2a52189b8bda90c75a780614fedf2c2/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136333334353333392f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/163345339)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/354c0f8e2c565400a89bc0acbe5b499a477f63f633f2301a21b38de1e53009a8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f76696c64616e62696e612f6c61726176656c2d6475706c69636174652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vildanbina/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 vildanbina/laravel-duplicate

```

### Usage

[](#usage)

##### Step 1

[](#step-1)

Your Eloquent models should use the `vildanbina\Duplicate\Traits\HasDuplicates` trait and the `vildanbina\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:

```
