PHPackages                             bfg/eloquent-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. bfg/eloquent-duplicate

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

bfg/eloquent-duplicate
======================

Duplicate any Eloquent model along with its underlying relationships

6.0.0(3y ago)071MITPHPPHP ^7.4|^8.0|^8.1

Since Dec 28Pushed 3y agoCompare

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

READMEChangelogDependencies (5)Versions (10)Used By (0)

### This is fork from Bfg/eloquent-duplicate to make it works with new Laravel 8.x|9.x

[](#this-is-fork-from-bfgeloquent-duplicate-to-make-it-works-with-new-laravel-8x9x)

---

### Duplicate any Eloquent model along with its relationships

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

- [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 bfg/eloquent-duplicate

```

### Usage

[](#usage)

##### Step 1

[](#step-1)

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

```
