-
app/Events/ProfileImageUploaded.php
Open in GitHubuse App\Models\User; class ProfileImageUploaded { public function __construct(User $user) { $this->user = $user; } }
-
app/Listeners/ResizeImage.php
Open in GitHubuse Illuminate\Support\Facades\Storage; use Intervention\Image\Facades\Image; class ResizeImage { public function handle($event) { $file = Storage::disk('avatar')->get("{$event->user->image}"); Image::make($file) ->resize(100, 100) ->save(config('filesystems.disks.avatar.root')."/{$event->user->image}"); } }
-
app/Providers/EventServiceProvider.php
Open in GitHubuse App\Events\ProfileImageUploaded; use App\Listeners\ResizeImage; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { protected $listen = [ // ProfileImageUploaded::class => [ ResizeImage::class, ], ]; // }
-
app/Http/Livewire/Profile/UpdateImage.php
Open in GitHubuse App\Events\ProfileImageUploaded; use Livewire\Component; class UpdateImage extends Component { public function submit() { // ProfileImageUploaded::dispatch($this->user); // } // }