2017 © Pedro Peláez
 

library laravel-event-subscriber

This makes your event subscribers a little cleaner

image

oldtimeguitarguy/laravel-event-subscriber

This makes your event subscribers a little cleaner

  • Thursday, August 11, 2016
  • by oldtimeguitarguy
  • Repository
  • 1 Watchers
  • 1 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

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., (*1)

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

This class eliminates that., (*3)

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., (*4)

Instead, just prefix all of your event names with on as public methods., (*5)

So you would do something like this:, (*6)

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

The Versions

11/08 2016

dev-master

9999999-dev

This makes your event subscribers a little cleaner

  Sources   Download

MIT

by Karl Hepler

19/07 2016

v1.1.2

1.1.2.0

This makes your event subscribers a little cleaner

  Sources   Download

MIT

by Karl Hepler

19/07 2016

v1.1.1

1.1.1.0

This makes your event subscribers a little cleaner

  Sources   Download

MIT

by Karl Hepler

19/07 2016

v1.1.0

1.1.0.0

This makes your event subscribers a little cleaner

  Sources   Download

MIT

by Karl Hepler

09/07 2016

v1.0.1

1.0.1.0

This makes your event subscribers a little cleaner

  Sources   Download

MIT

by Karl Hepler