Skip to content

jackabox/nova-duplicate-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8b28990 · Jul 21, 2022

History

39 Commits
May 23, 2019
Nov 27, 2019
Oct 31, 2018
Nov 27, 2019
Oct 31, 2018
Nov 27, 2019
Feb 7, 2019
May 28, 2019
Jul 21, 2022
Nov 27, 2019
May 14, 2019
Aug 21, 2019
Nov 28, 2018

Repository files navigation

Laravel Nova Duplicate Model

No Longer Maintained

This plugin is no longer maintained. I've had no time to maintain this as I don't use Nova anymore. I'm looking for someone to take over this and handle it, let me know if you want to maintain it! See Issue #33.

Information

GitHub release (latest by date) Packagist GitHub

Allow users to duplicate a record through the Laravel Nova Admin Panel along with any relations that are required (currently works with HasMany).

Installation

composer require jackabox/nova-duplicate-field

Reference the duplicate field at the top of your Nova resource and then include the necessary code within the fields.

use Jackabox\DuplicateField\DuplicateField
DuplicateField::make('Duplicate')
    ->withMeta([
        'resource' => 'specialisms', // resource url
        'model' => 'App\Models\Specialism', // model path
        'id' => $this->id, // id of record
        'relations' => ['one', 'two'], // an array of any relations to load (nullable).
        'except' => ['status'], // an array of fields to not replicate (nullable).
        'override' => ['status' => 'pending'] // an array of fields and values which will be set on the modal after duplicating (nullable).
    ]),

Duplicate field only works on the index view at the moment (plans to expand this are coming) and already passes through onlyOnIndex() as an option.

Hooking Into Replication

Duplicate Field uses a relatively standard replicate method which is available via the Eloquent model. To modify data as you are duplicating the field use an observer on the replicating method.

Issues

If there are any issues or requests feel free to open a GitHub issue or a pull request.

Todo

  • Duplicate relations alongside the main post.
    • Integrate reattaching of relations, rather than needing to duplicate (i.e. belongsToMany)
  • Catch errors to the end user.
  • Alert for the user (confirmation possibly).
  • Documentation on how to hide/show when needed.
  • Documentation on how to hook into replication.
  • Add a button to the resource view.
  • Clean up methods for v1