Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Declaration of App\Providers\EventServiceProvider::boot

I'm currently updating to Laravel 5.4 and have encountered the following error in the console.

Declaration of App\Providers\EventServiceProvider::boot(Illuminate\Contract
s\Events\Dispatcher $events) should be compatible with Illuminate\Foundatio
n\Support\Providers\EventServiceProvider::boot()

Here is my composer.json

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.4.*",
    "illuminate/html": "5.0.*",
    "laravelcollective/html": "^5.4.0"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~5.7",
    "symfony/css-selector": "2.8.*|3.0.*",
    "symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ]
},
"config": {
    "preferred-install": "dist"
}
}
like image 285
Marcus Christiansen Avatar asked Jun 27 '17 19:06

Marcus Christiansen


People also ask

How will you register service providers in Laravel?

Registering ProvidersAll service providers are registered in the config/app. php configuration file. This file contains a providers array where you can list the class names of your service providers. By default, a set of Laravel core service providers are listed in this array.

What is AppServiceProvider in Laravel?

The AppServiceProvider is the ability for us to provide services to the application. Inside of this file, there's two separate methods, register and boot. Register is used to register those classes that you want to make available inside of your Laravel application that are not dependent upon any other classes.

What is Laravel boot function?

In laravel eloquent model have a magical method is called the boot() method. You can override the default behavior. Suppose you want to set up some field value at the moment of creating the model in laravel then you can declare the field's value in the boot() method.

What is service provider in Laravel 8?

Service providers are the central place to configure your application. If you open the config/app. php file included with Laravel, you will see a providers array. These are all of the service provider classes that will be loaded for your application.


2 Answers

You're updating to 5.4, so some things are going to change.

The boot method no longer requires an argument passed to it, nor does the parent:

Remove the argument completely from both the function, and the parent::boot() so no arguments are passed to either:

public function boot() 
{
    parent::boot();
}
like image 101
Ohgodwhy Avatar answered Sep 21 '22 18:09

Ohgodwhy


I think your application might be caching the compiled files, One solution worked for me after upgrading, is to recreate a fresh empty directory of:

bootstrap/cache

Rename the existing folder to different temp name, and create a new directory bootstrap/cache and apply the permissions/ownership , and you are good to go.

like image 20
Mahmoud Abdelsattar Avatar answered Sep 20 '22 18:09

Mahmoud Abdelsattar