Skip to content

Commit

Permalink
Allow overriding the default media observer. (#3763)
Browse files Browse the repository at this point in the history
* Allow overriding the default media observer.

* Update MediaLibraryServiceProvider.php

---------

Co-authored-by: Freek Van der Herten <[email protected]>
  • Loading branch information
hailwood and freekmurze authored Jan 13, 2025
1 parent 7ee8bb7 commit 7fa1ede
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/media-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
*/
'media_model' => Spatie\MediaLibrary\MediaCollections\Models\Media::class,

/*
* The fully qualified class name of the media observer.
*/
'media_observer' => Spatie\MediaLibrary\MediaCollections\Models\Observers\MediaObserver::class,

/*
* When enabled, media collections will be serialised using the default
* laravel model serialization behaviour.
Expand Down
3 changes: 2 additions & 1 deletion src/MediaLibraryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public function configurePackage(Package $package): void
public function packageBooted(): void
{
$mediaClass = config('media-library.media_model', Media::class);
$mediaObserverClass = config('media-library.media_observer', MediaObserver::class);

$mediaClass::observe(new MediaObserver);
$mediaClass::observe(new $mediaObserverClass);
}

public function packageRegistered(): void
Expand Down

0 comments on commit 7fa1ede

Please sign in to comment.