PHP工匠突然不起作用

Dar*_*oBB 11 php laravel laravel-5 artisan laravel-5.2

我已经开始学习Laravel了.到目前为止,一切都运作良好.我正在按照本教程进行操作,并且我第7集陷入了困境.

问题是我不能再开始工匠了.我试图安装修补匠,我可能已经更新了工匠,所以我最终没有工匠和修补匠.我使用的是Linux Ubuntu 12.04 LTS.我已经通过命令行安装了所有内容.之后我试着跑:

php artisan --version

出现以下问题:

[ErrorException]
App\Providers\EventServiceProvider :: boot()的声明应与Illuminate\Foundation\Support\Providers\EventServiceProvider :: boot
()兼容

这是我的文件的app/Providers/EventServiceProvider.php样子:

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

        //
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Laravel 5.2和我的composer.json它看起来像这样:

"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"doctrine/dbal": "^2.6@dev",
"vluzrmos/tinker": "dev-master",
"moon/artisan": "dev-master"
Run Code Online (Sandbox Code Playgroud)

我在这里看到过类似的问题,例如:

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

但从来没有直接给出答案,实际上我不明白如何解决这个问题?我需要直接回答,因为我是Laravel的新手.可以通过Linux命令行以某种方式更新工匠,以便它可以再次工作吗?

gre*_*eut 9

显然,新boot()方法没有任何争论.您必须对三个提供程序应用一些更改.

     /**
      * 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();

         //
     }
Run Code Online (Sandbox Code Playgroud)

查看此提交以获取完整的更改列表.

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


cyt*_*nny 8

与@greut答案类似,但如果它是由升级laravel引起的(如果您正在安装其他程序包composer update并且您的laravel版本可能会触发dev-master),则需要更改参数的2个位置.

App\Providers\RouteServiceProvider
App\Providers\EventServiceProvider
Run Code Online (Sandbox Code Playgroud)

在两个控制器中,都有一个名为的方法boot().将参数更改为空.即

public function boot(/*original something here. empty it*/)
{
    parent::boot(/*original something here. empty it*/);
}
Run Code Online (Sandbox Code Playgroud)

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


Ala*_*orm 2

严格从 PHP 的角度来看,当 artisan 尝试启动其 CLI 应用程序时,您会收到此错误

App\Providers\EventServiceProvider::boot() 的声明应与 Illuminate\Foundation\Support\Providers\EventServiceProvider::boot 兼容

您已经定义了一个类App\Providers\EventServiceProvider。这个类有Illuminate\Foundation\Support\Providers\EventServiceProvider一个父类/祖先(别名与ServiceProvider你的类中一样)。

您的 启动方法Illuminate\Foundation\Support\Providers\EventServiceProvider有一组参数。您已boot在 中定义App\Providers\EventServiceProvider,并以某种方式更改了这些参数(更少的参数、不同的类型提示、不同/无默认值等)。

你不能那样做。

让你boot与父类兼容,你就能解决你的问题。

(但是,这可能无法解决您的所有问题,因为注释听起来像是您正在使用 Laravel 的未发布版本,该版本可能与教程中的内容有所不同)