Skip to content

Commit

Permalink
Merge pull request #12829 from WayneHarris/feat/3.x-support-overide-m…
Browse files Browse the repository at this point in the history
…edia-model

feat: add support to override media model on spatie media file upload
  • Loading branch information
danharrin committed May 17, 2024
2 parents 15f2f47 + 554da25 commit 66f7a2b
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ protected function setUp(): void
return $media->getAttributeValue('uuid');
});

$this->reorderUploadedFilesUsing(static function (SpatieMediaLibraryFileUpload $component, array $state): array {
$this->reorderUploadedFilesUsing(static function (SpatieMediaLibraryFileUpload $component, ?Model $record, array $state): array {
$uuids = array_filter(array_values($state));

$mediaClass = config('media-library.media_model', Media::class);
$mediaClass = ($record && method_exists($record, 'getMediaModel')) ? $record->getMediaModel() : null;
$mediaClass ??= config('media-library.media_model', Media::class);

$mappedIds = $mediaClass::query()->whereIn('uuid', $uuids)->pluck('id', 'uuid')->toArray();

Expand Down

0 comments on commit 66f7a2b

Please sign in to comment.