-
app/Observers/MediaObserver.php
Open in GitHubuse Spatie\MediaLibrary\MediaCollections\Models\Media; class MediaObserver { public function created(Media $media): void { if (! auth()->check()) { return; } auth()->user()->modifyImageUploadedSize($media->size); } public function deleted(Media $media): void { if (! auth()->check()) { return; } auth()->user()->modifyImageUploadedSize($media->size * -1); } }
-
app/Providers/EventServiceProvider.php
Open in GitHubuse App\Models; use App\Observers; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Spatie\MediaLibrary\MediaCollections\Models\Media; class EventServiceProvider extends ServiceProvider { // ... public function boot(): void { Models\DailyView::observe(Observers\DailyViewObserver::class); Models\ImageUpload::observe(Observers\ImageUploadObserver::class); Models\Presentation::observe(Observers\PresentationObserver::class); Media::observe(Observers\MediaObserver::class); } // ... }