Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tormjens/eventy
Browse files Browse the repository at this point in the history
  • Loading branch information
tormjens committed Nov 17, 2020
2 parents 75cb4c1 + 6823772 commit b1d87d0
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Anywhere in your code you can create a new action like so:
```php
use TorMorten\Eventy\Facades\Events as Eventy;

Eventy::action('my.hook', 'awesome');
Eventy::action('my.hook', $user);
```

The first parameter is the name of the hook; you will use this at a later point when you'll be listening to your hook. All subsequent parameters are sent to the action as parameters. These can be anything you'd like. For example you might want to tell the listeners that this is attached to a certain model. Then you would pass this as one of the arguments.
Expand All @@ -74,9 +74,11 @@ To listen to your hooks, you attach listeners. These are best added to your `App

For example if you wanted to hook in to the above hook, you could do:

```
Eventy::addAction('my.hook', function($what) {
echo 'You are '. $what;
```php
Eventy::addAction('my.hook', function($user) {
if ($user->is_awesome) {
$this->doSomethingAwesome($user);
}
}, 20, 1);
```

Expand Down Expand Up @@ -121,7 +123,7 @@ Given you have added the `EventBladeServiceProvider` to your config, there are t
Adding the same action as the one in the action example above:

```
@action('my.hook', 'awesome')
@action('my.hook', $user)
```

Adding the same filter as the one in the filter example above:
Expand Down Expand Up @@ -178,6 +180,51 @@ class PluginBServiceProvider extends ServiceProvider
}
```

Here's an example of an action being added to the a blade template for extensibility by plugins that can be conditionally loaded. Abstracting controller dependancies within your template views.


```
@foreach ($posts as $post)
...
<p>{{ $post->body }}</p>
...
@action('blade-posts-loop-post-footer', $post)
@endforeach
```

This would allow for your plugins/controllers to hook into each blog post footer.

In this example a share link is added.
```php
use TorMorten\Eventy\Facades\Events as Eventy;
class SharePostsController
{
public function boot()
{
Eventy::addAction('blade-posts-loop-post-footer', function($post) {
echo '<a href="twitter.com?share='.$post->url.'">Twitter</a>';
printf('<a href="https://xyz.com?share='.$post->url.'">XYZbook</a>');
});
}
}
```

In this example a comment count is added.
```php
use TorMorten\Eventy\Facades\Events as Eventy;
class CommentsPostsController
{
public function boot()
{
Eventy::addAction('blade-posts-loop-post-footer', function($post) {
echo 'Comments: ' . count($post->comments);
});
}
}
```



## Credits
- Created by [Tor Morten Jensen](https://twitter.com/tormorten)
- Logo by [Caneco](https://twitter.com/caneco)

0 comments on commit b1d87d0

Please sign in to comment.