0
votes

I want to define a service provider that registers events. So have done the following (taken from a book)

<?php
namespace MyApp\Providers;
use Illuminate\Support\ServiceProvider;

class EventsProvider extends ServiceProvider 
{

     public function boot()
     {
         Event::listen('some.event', function($parameter)
         {
             // Handle the event..
         });
     }
}

Then I added it to the provider array.

But when I execute the code I get the following error

implement the remaining methods (Illuminate\Support\ServiceProvider::register)

It compels me to declare a register() method.

When I add to the EventsProvider class a method named register() (without implementation, and just make it return null) I get the following error

Class 'MyApp/Providers/EventProvider' not found

Why is that, and how can I solve it?

1

1 Answers

2
votes

You just need to declare it, because it's declared in the Interface:

<?php namespace MyApp\Providers;

use Illuminate\Support\ServiceProvider;

class EventsProvider extends ServiceProvider {

    public function boot()
    {
          Event::listen('some.event', function($parameter)
          {
                // Handle the event..
           });
    }

    public function register() 
    {
    }

}

Then execute

composer dump-autoload --optimize

But you might also have a typo somewhere because it says Class 'MyApp/Providers/EventProviders' not found, but it should be MyApp/Providers/EventProvider.