Skip to content

Commit

Permalink
leave the ability to override media model (#3543)
Browse files Browse the repository at this point in the history
  • Loading branch information
illambo authored Feb 17, 2024
1 parent 1d36f09 commit b575967
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/InteractsWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function bootInteractsWithMedia()

public function media(): MorphMany
{
return $this->morphMany(config('media-library.media_model'), 'model');
return $this->morphMany($this->getMediaModel(), 'model');
}

/**
Expand Down Expand Up @@ -263,6 +263,11 @@ public function getMediaRepository(): MediaRepository
return app(MediaRepository::class);
}

public function getMediaModel(): string
{
return config('media-library.media_model');
}

public function getFirstMedia(string $collectionName = 'default', $filters = []): ?Media
{
$media = $this->getMedia($collectionName, $filters);
Expand Down Expand Up @@ -378,7 +383,7 @@ public function updateMedia(array $newMediaArray, string $collectionName = 'defa
{
$this->removeMediaItemsNotPresentInArray($newMediaArray, $collectionName);

$mediaClass = config('media-library.media_model');
$mediaClass = $this->getMediaModel();
$mediaInstance = new $mediaClass();
$keyName = $mediaInstance->getKeyName();

Expand Down

0 comments on commit b575967

Please sign in to comment.