Skip to content

Commit

Permalink
updated events.md
Browse files Browse the repository at this point in the history
Added 3 more events to List of events.
Added How to use events using Event Subscribers.
  • Loading branch information
mohamed-aiman authored Nov 20, 2016
1 parent 863820d commit 72eb4eb
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions doc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

## List of events
* Unisharp\Laravelfilemanager\Events\ImageWasUploaded
* Unisharp\Laravelfilemanager\Events\ImageWasRenamed
* Unisharp\Laravelfilemanager\Events\ImageWasDeleted
* Unisharp\Laravelfilemanager\Events\FolderWasRenamed

## How to use

Expand Down Expand Up @@ -42,3 +45,47 @@ class UploadListener
}
}
```

Or by using Event Subscribers

Snippet for `EventServiceProvider`
```php
protected $subscribe = [
UploadListener::class
];
```
The `UploadListener` will look like:
```php
public function subscribe($events)
{
$events->listen('*', UploadListener::class);
}

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
}

public function onImageWasRenamed(ImageWasRenamed $event)
{
// image was renamed
}

public function onImageWasDeleted(ImageWasDeleted $event)
{
// image was deleted
}

public function onFolderWasRenamed(FolderWasRenamed $event)
{
// folder was renamed
}

0 comments on commit 72eb4eb

Please sign in to comment.