Allow users to duplicate a record through the Laravel Nova Admin Panel along with any relations that are required (currently works with HasMany).
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', $this->model(), static::uriKey()),
Pass an array of attributes to not replicate.
DuplicateField::make('Duplicate', $this->model(), static::uriKey())
->except(['status']),
Pass an array of attributes with values to override.
DuplicateField::make('Duplicate', $this->model(), static::uriKey())
->override(['status' => 'pending']),
Pass an array of relations to replicate also.
DuplicateField::make('Duplicate', $this->model(), static::uriKey())
->relations(['translations']),
Pass an array of attributes for each relation to not replicate.
DuplicateField::make('Duplicate', $this->model(), static::uriKey())
->relations(['translations'])
->relationsExcept([
'translations' => ['slug'],
]),
Pass an array of attributes for each relation to override.
DuplicateField::make('Duplicate', $this->model(), static::uriKey())
->relations(['translations'])
->relationsOverride([
'translations' => ['title' => 'New value'],
]),
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.
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.
If there are any issues or requests feel free to open a GitHub issue or a pull request.
- 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