You can also define classes to handle specific events, and then use the service provider to register them.
The following is a basic example:
application /NewUserListener.php
The listener that is called when the event fires:
class NewUserListener { public function handle($uid) {
application /ListenerServiceProvider.php
ServiceProvider - remember and add this to the list of service providers in the L4 configuration.
use Illuminate\Support\ServiceProvider; class ListenerServiceProvider extends ServiceProvider { public function register() { Event::listen('myapp.new_user', 'NewUserListener');
If you organize listeners, etc. in folders with the appropriate name, it becomes much easier to maintain if you have a bunch of listeners later. You can also create and test listeners if you write them this way.
Darren taylor
source share