New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

oldtimeguitarguy/laravel-event-subscriber

This makes your event subscribers a little cleaner
37
Install
composer require oldtimeguitarguy/laravel-event-subscriber
Latest Version:v1.1.2
License:MIT
Last Updated:Aug 11, 2016
Links: GitHub  ·  Packagist
Maintainer: oldtimeguitarguy

Laravel Event Subscriber

Installation

  1. composer require oldtimeguitarguy/laravel-event-subscriber
  2. Add OldTimeGuitarGuy\LaravelEventSubscriber\EventSubscriberProvider::class, to the providers array in config/app.php
  3. Run php artisan vendor:publish to copy the config file to config/event_subscriber.php

Usage

  1. Create subscribers with php artisan make:event-subscriber SubscriberName
  2. Add custom event classes in config/event_subscriber.php

Description

The basic premise of this evolved from here.

I love the idea, but I don't like how you have to define that subscribe method.

This class eliminates that.

Basically create your event subscriber class just like the documentation says, but now, if you extend from this class, you never have to write the subscribe method.

Instead, just prefix all of your event names with on as public methods.

So you would do something like this:

class MyEventSubscriber extends EventSubscriber
{
    public function onUserLogin($event)
    {
        // do stuff
    }

    public function onUserLogout($event)
    {
        // do stuff
    }
}

That's it. There are a couple of caveats:

  1. It looks for the events in Laravel's app/Events directory. (or any class you add to the classmap in the config file)
  2. You can have a maximum of one subdirectory under app/Events/
  3. Be careful about name collisions, even if the event classes exist in different subdirectories under app/Events

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

665,354,487 9,703
laravel/framework

The Laravel Framework.

633,434,998 35,124
laravel/tinker

Powerful REPL for the Laravel framework.

539,265,140 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

458,029,405 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

431,187,642 4,660

Version History

Version Released License
v1.1.2 MIT
v1.1.1 MIT
v1.1.0 MIT
v1.0.1 MIT