-
app/Observers/ImageObserver.php
Open in GitHubuse App\Jobs\CalculateUsedDiskSpace; use App\Jobs\GenerateImageThumbnail; use App\Models\Image; use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Storage; class ImageObserver { public function created(Image $image) { $queue = [new GenerateImageThumbnail($image)]; if (request()->user()) { $queue[] = new CalculateUsedDiskSpace(request()->user()); } Bus::chain($queue)->dispatch(); } public function deleted(Image $image) { Storage::delete('images/' . $image->getResourceName()); foreach (Image::$supportedSizes as $size) { Storage::delete('images/' . $image->getResourceName($size . 'x' . $size)); } if (request()->user()) { CalculateUsedDiskSpace::dispatch(request()->user()); } } }
-
app/Providers/AppServiceProvider.php
Open in GitHubuse App\Models\Image; use App\Observers\ImageObserver; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { // public function boot() { // Image::observe(ImageObserver::class); // } }