11
votes

I have started to learn Laravel. Until now, everything worked perfectly. I'm following this tutorial and I'm stuck with episode 7.

The problem is that I cannot start artisan anymore. I have tried to install tinker, and I've probably updated artisan so I ended up without artisan and tinker. I am using Linux Ubuntu 12.04 LTS. I have installed everything via command line. After that I tried to run:

php artisan --version

The following problem occurs:

[ErrorException]
Declaration of App\Providers\EventServiceProvider::boot() should be compati ble with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot
()

This is how my file app/Providers/EventServiceProvider.php looks like:

<?php

namespace App\Providers;

use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\SomeEvent' => [
            'App\Listeners\EventListener',
        ],
    ];

    /**
     * Register any other events for your application.
     *
     * @param  \Illuminate\Contracts\Events\Dispatcher  $events
     * @return void
     */
    public function boot(DispatcherContract $events)
    {
        parent::boot($events);

        //
    }
}

I'm using Laravel 5.2 and my composer.json it looks like this:

"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"doctrine/dbal": "^2.6@dev",
"vluzrmos/tinker": "dev-master",
"moon/artisan": "dev-master"

I've seen similar problems here for example:

https://laracasts.com/discuss/channels/general-discussion/l5-composer-update-ends-with-an-error-suddenly

https://laracasts.com/discuss/channels/laravel/event-service-provider-in-package

but never the answer was given directly and actually I do not understand how to solve this problem? I would need direct answer because I'm newbie in Laravel. Can artisan be updated somehow easy with Linux command line so it can work again?

4
Laravel 5.2 hasn't even been released yet.lukasgeiter
Like he said...Change your version to Laravel 5.1Neo Ighodaro

4 Answers

9
votes

Apparently, the new boot() method doesn't take any argument. You'll have to apply some changes to the three providers.

     /**
      * Register any other events for your application.
      *
-     * @param  \Illuminate\Contracts\Events\Dispatcher  $events
      * @return void
      */
-    public function boot(DispatcherContract $events)
+    public function boot()
     {
-        parent::boot($events);
+        parent::boot();

         //
     }

Check out this commit for the full list of changes.

https://github.com/laravel/laravel/commit/2b05ce3b054593f7622c1be6c4c6aadc1c5a54ae

8
votes

Similar to @greut answer, but if it is caused by upgrading laravel (which may be triggered if you are installing other package through composer update and your version for laravel is dev-master), there are 2 places that you need to change the parameter.

App\Providers\RouteServiceProvider
App\Providers\EventServiceProvider

In both controller, there is a method named boot(). Change the parameter to empty. i.e.

public function boot(/*original something here. empty it*/)
{
    parent::boot(/*original something here. empty it*/);
}

Reference: https://laracasts.com/discuss/channels/forge/laravel-53-update-causing-error-on-forge-only/replies/189654

3
votes

I encountered the same problem in forge while performing the upgrade to 5.3, you need to get rid of bootstrap/cache and as you mentioned artisan won’t launch because of that error so you need to do it the old way: rm -R bootstrap/cache and then mkdir bootstrap/cache. Don’t forget to apply the correct permissions of bootstrap/cache after you’re done.

2
votes

Speaking strictly from a PHP point of view, when artisan tries to start up its CLI application, and you get this error

Declaration of App\Providers\EventServiceProvider::boot() should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot

You've defined a class App\Providers\EventServiceProvider. This class has Illuminate\Foundation\Support\Providers\EventServiceProvider as an parent/ancestor (aliased as ServiceProvider in your class).

The boot method in your Illuminate\Foundation\Support\Providers\EventServiceProvider has a set of arguments. You have defined boot in App\Providers\EventServiceProvider, and changed those arguments somehow (fewer arguments, different type hints, different/no defaults, etc.).

You can't do that.

Make you boot compatible with the parent class, and you'l fix your problem.

(This, however, might not fix all your problems, as the comments make it sound like you're using an unreleased version of Laravel that may differ from what's in a tutorial)