diff --git a/dist/js/field.js b/dist/js/field.js index 31544b2..4a38ec8 100644 --- a/dist/js/field.js +++ b/dist/js/field.js @@ -958,7 +958,8 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); model: this.field.model ? this.field.model : "", id: this.field.id ? this.field.id : "", resource: this.field.resource ? this.field.resource : "", - relations: this.field.relations ? this.field.relations : "" + relations: this.field.relations ? this.field.relations : "", + mediaCollection: this.field.mediaCollection ? this.field.mediaCollection : "", }).then(function (response) { window.location.replace(response.data.destination); }).catch(function (error) { @@ -2110,4 +2111,4 @@ if (false) { } /***/ }) -/******/ ]); \ No newline at end of file +/******/ ]); diff --git a/resources/js/components/IndexField.vue b/resources/js/components/IndexField.vue index 9c7f2e8..d80e66b 100644 --- a/resources/js/components/IndexField.vue +++ b/resources/js/components/IndexField.vue @@ -33,7 +33,8 @@ export default { model: this.field.model ? this.field.model : "", id: this.field.id ? this.field.id : "", resource: this.field.resource ? this.field.resource : "", - relations: this.field.relations ? this.field.relations : "" + relations: this.field.relations ? this.field.relations : "", + mediaCollection: this.field.mediaCollection ? this.field.mediaCollection : "" }) .then(response => { window.location.replace(response.data.destination); diff --git a/src/Http/Controllers/DuplicateController.php b/src/Http/Controllers/DuplicateController.php index fa410df..701e5c6 100644 --- a/src/Http/Controllers/DuplicateController.php +++ b/src/Http/Controllers/DuplicateController.php @@ -25,6 +25,15 @@ public function duplicate(Request $request) $newModel = $model->replicate(); $newModel->push(); + + // Duplicate spatie media if we are using the package + if(method_exists($model, 'getMedia') && method_exists($model, 'copyMedia') && $request->mediaCollection) { + $images = $model->getMedia($request->mediaCollection); + + foreach ($images as $image) { + $newModel->copyMedia($image->getPath())->toMediaCollection($request->mediaCollection); + } + } if (isset($request->relations) && !empty($request->relations)) { // load the relations