PHPackages                             numesia/laravel-events - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. numesia/laravel-events

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

numesia/laravel-events
======================

Laravel package that helps to send events across components

0.0.13(3y ago)0882MITPHPPHP &gt;=5.5.9

Since Jul 20Pushed 3y ago3 watchersCompare

[ Source](https://github.com/NUMESIA/NU_EVENT_LaravelPackage)[ Packagist](https://packagist.org/packages/numesia/laravel-events)[ RSS](/packages/numesia-laravel-events/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (14)Used By (0)

NU\_EVENTS\_LaravelPackage
==========================

[](#nu_events_laravelpackage)

Laravel package that helps to send events across components

This laravel event package is a private package so we can't just require it using composer, that's why we have to add a vcs repository to tell composer from which url the package must be loaded.

```
"repositories": [
    {
        "type": "vcs",
        "url":  "git@github.com:NUMESIA/NU_EVENT_LaravelPackage.git"
    }
],
"require": {
    "NUMESIA/laravel-events": "0.0.*"
},

```

Once this has finished, you will need to add the service provider to the providers array in your app.php config as follows:

```
Numesia\NuEvent\Providers\NuEventServiceProvider::class,

```

Next, also in the app.php config file, under the aliases array, you may want to add NuEvent facades.

```
'NuEvent' => Numesia\NuEvent\Facades\NuEvent::class,

```

Then publish configs

```
php artisan vendor:publish --provider="Numesia\NuEvent\Providers\NuEventServiceProvider" --tag=config

```

Finally, you will want to change your `NUEVENT_TOKEN` key from `.env` file:

```
NUEVENT_TOKEN=YourEventSecretKey

```

How to use ?
------------

[](#how-to-use-)

NuEvent comes with a global function nuEvent() which help you te send easily events to other components

```
    /**
     * Send an event to components
     *
     * @param           $eventName   The event name
     * @param           $eventData   The event data
     * @param            $components  The components
     * @param          $callback    The callback
     */
    function nuEvent($eventName, $eventData, $components = null, $callback)

```

> $components can be a string (bpm), an array \['bpm', 'cms'\] or nothing to broadcast to all components

You can Also use the Facade NuEvent if you want to perform the same task

```
/**
 * Emit event to component name
 *
 * @param        $componentName  The component name
 * @param        $eventName      The event name
 * @param        $eventData      The event data
 */
NuEvent::emit($componentName, $eventName, $eventData)

/**
 * Broadcast event to all components
 *
 * @param        $eventName   The event name
 * @param        $eventData   The event data
 */
NuEvent::broadcast($eventName, $eventData)

/**
 * Dispatch event to selected components
 *
 * @param        $eventName   The event name
 * @param        $eventData   The event data
 * @param         $components  The components
 */
NuEvent::dispatch($eventName, $eventData, $components = null)

```

> /!\\ When you send an event, NuEvent add automatically a suffix '**nuEvents:**' to your event name

### Example

[](#example)

In this example we will try to send an event from book to bpm

#### BOOK Component

[](#book-component)

All we have to do is adding this command somewhere

```
nuEvent('book.ping', "Hello World", "bpm");

```

#### BPM Component

[](#bpm-component)

We should create a listener (don't forget to add it into your EventServiceProvider)

- EventServiceProvider

```
//EventServiceProvider
protected $subscribe = [
    'App\Listeners\NuEventSubscriber',
];

```

- NuEventSubscriber

```
// App\Listeners\NuEventSubscriber
