spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

Added callback to manipulate FileAdder when performing a copy #3658

Closed chrispage1 closed 4 months ago

chrispage1 commented 4 months ago

This feature adds the ability to customise the FileAdder options when performing a copy action.

In my case, the requirement for this is to set properties against the media item, but it gives the user access to all of the FileAdder methods. Example:

use Spatie\MediaLibrary\MediaCollections\FileAdder;;

$media->copy(
    $postModel,
    fileAdderCallback: fn (FileAdder $adder): FileAdder => $adder->withProperties([
        'duplicate_of' => $oldMedia->getKey(),
    ])
);

Thanks!

freekmurze commented 4 months ago

Thank you!