This is the documentation for
v9 but the latest version is
v10
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-medialibrary
You can move media from one model to another with the move
method.
$mediaItem = $model->getMedia()->first();
$movedMediaItem = $mediaItem->move($anotherModel, 'new-collection', 's3');
Any conversions defined on $anotherModel
will be performed. The name
and the custom_properties
will be transferred as well.
##Copying media
You can also copy media from one model with the copy
method.
$mediaItem = $model->getMedia()->first();
$copiedMediaItem = $mediaItem->copy($anotherModel, 'new-collection', 's3');