diff --git a/README.md b/README.md index 42354321..10edef4d 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,42 @@ PR is welcome! ![FileManager screenshot 2](http://unisharp.com/img/filemanager2.png) +## Events + +To use events you can add a listener to listen to the events + +Snippet for `EventServiceProvider` +```php + protected $listen = [ + ImageWasUploaded::class => [ + UploadListener::class, + ], + ]; +``` + +The `UploadListener` will look like: +```php +class UploadListener +{ + public function handle($event) + { + $method = 'on'.class_basename($event); + if (method_exists($this, $method)) { + call_user_func([$this, $method], $event); + } + } + + public function onImageWasUploaded(ImageWasUploaded $event) + { + $path = $event->path(); + //your code, for example resizing and cropping + } +} +``` + +List of events: + * Unisharp\Laravelfilemanager\Events\ImageWasUploaded + ## Credits * All contibutors from GitHub. (issues / PR) * Special thanks to diff --git a/src/Events/ImageWasUploaded.php b/src/Events/ImageWasUploaded.php new file mode 100644 index 00000000..07ee0362 --- /dev/null +++ b/src/Events/ImageWasUploaded.php @@ -0,0 +1,22 @@ +path = $path; + } + + /** + * @return string + */ + public function path() + { + return $this->path; + } + +} diff --git a/src/controllers/UploadController.php b/src/controllers/UploadController.php index cdcb9bd9..3f891e0f 100644 --- a/src/controllers/UploadController.php +++ b/src/controllers/UploadController.php @@ -1,5 +1,6 @@ makeThumb($dest_path, $new_filename); } + Event::fire(new ImageWasUploaded(realpath($dest_path.'/'.$new_filename))); + // upload via ckeditor 'Upload' tab if (!Input::has('show_list')) { return $this->useFile($new_filename);