I used composer to upgrade to Laravel 5.3, which broke it

女生的网名这么多〃 提交于 2019-12-10 14:07:20

问题


Here's the exception I get now when I try to run my page. I've tried removing and recreating the bootstrap/cache based on some recommendations I've seen online. I've tried removing the arguments in the ServiceProvider files for the boot method. Nothing works.

ErrorException in EventServiceProvider.php line 9:
Declaration of App\Providers\EventServiceProvider::boot() should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot()
in EventServiceProvider.php line 9
at HandleExceptions->handleError('2048', 'Declaration of App\Providers\EventServiceProvider::boot() should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot()', 'C:\xampp\htdocs\laravel\app\Providers\EventServiceProvider.php', '9', array('file' => 'C:\xampp\htdocs\laravel\vendor\composer/../../app\Providers\EventServiceProvider.php')) in EventServiceProvider.php line 9
at include('C:\xampp\htdocs\laravel\app\Providers\EventServiceProvider.php') in ClassLoader.php line 414
at Composer\Autoload\includeFile('C:\xampp\htdocs\laravel\vendor\composer/../../app\Providers\EventServiceProvider.php') in ClassLoader.php line 301
at ClassLoader->loadClass('App\Providers\EventServiceProvider')
at spl_autoload_call('App\Providers\EventServiceProvider') in ProviderRepository.php line 146
at ProviderRepository->createProvider('App\Providers\EventServiceProvider') in ProviderRepository.php line 74
at ProviderRepository->load(array('Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'Collective\Html\HtmlServiceProvider', 'App\Providers\AppServiceProvider', 'App\Providers\AuthServiceProvider', 'App\Providers\EventServiceProvider', 'App\Providers\RouteServiceProvider')) in Application.php line 540
at Application->registerConfiguredProviders() in RegisterProviders.php line 17
at RegisterProviders->bootstrap(object(Application)) in Application.php line 203
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 254
at Kernel->bootstrap() in Kernel.php line 145
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54

Also, when I run "composer update", I get this exception:

EventServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Event;
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.
     *

     * @return void
     */
    public function boot()
    {
        parent::boot();

        //
    }
}

RouteServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *

     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    public function map(Router $router)
    {
        $this->mapWebRoutes($router);

        //
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    protected function mapWebRoutes(Router $router)
    {
        $router->group([
            'namespace' => $this->namespace, 'middleware' => 'web',
        ], function ($router) {
            require app_path('Http/routes.php');
        });
    }
}

AuthServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any application authentication / authorization services.
     *

     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        //
    }
}

回答1:


You need to remove the arguments from RouteServiceProvider and EventServiceProvider.

From the upgrade guide:

You may remove the arguments from the boot method on the EventServiceProvider, RouteServiceProvider, and AuthServiceProvider classes. Any calls to the given arguments may be converted to use the equivalent facade instead. So, for example, instead of calling methods on the $dispatcher argument, you may simply call the Event facade. Likewise, instead of making method calls to the $router argument, you may make calls to the Route facade, and instead of making method calls to the $gate argument, you may make calls to the Gate facade.

Laravel 5.2 EventServiceProvider example:

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);

        //
    }
}

Laravel 5.3 EventServiceProvider example:

namespace App\Providers;

use Illuminate\Support\Facades\Event;
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 events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        //
    }
}



回答2:


I found this answer

composer update --no-scripts

Which is getting me through an update of 5.1 to 5.2



来源:https://stackoverflow.com/questions/40935130/i-used-composer-to-upgrade-to-laravel-5-3-which-broke-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!