Laravel Artisan事件:生成命令抛出致命错误



我遵循Laravel 5.7关于事件注册和生成的官方文档:https://laravel.com/docs/5.7/events#generating-events-and-listeners

我有一个EventServiceProvider,定义了以下事件:

<?php
namespace AppProviders;
use IlluminateFoundationSupportProvidersEventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
'AppEventsFormBeforeCreate' => [
'AppListenersWebhookBeforeCreate',
],
'AppEventsFormAfterCreate' => [
'AppListenersNotifyAfterCreate',
'AppListenersWebhookAfterCreate',
],
'AppEventsFormBeforeUpdate' => [
'AppListenersWebhookBeforeUpdate',
],
'AppEventsFormAfterUpdate' => [
'AppListenersNotifyAfterUpdate',
'AppListenersWebhookAfterUpdate',
],
'AppEventsFormBeforeDelete' => [
'AppListenersWebhookBeforeDelete',
],
'AppEventsFormAfterDelete' => [
'AppListenersNotifyAfterDelete',
'AppListenersWebhookAfterDelete',
],
'AppEventsFormBeforeSave' => [
'AppListenersWebhookBeforeSave',
],
'AppEventsFormAfterSave' => [
'AppListenersNotifyAfterSave',
'AppListenersWebhookAfterSave',
],
];
/**
* The subscriber classes to register.
*
* @var array
*/
protected $subscribe = [
'AppListenersUserEventSubscriber',
];
/**
* Register any other events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
}
}

错误:

当我运行命令php artisan event:generate时,我得到以下错误:

PHP Fatal error:  Call to a member function listens() on null in /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/EventGenerateCommand.php on line 35

[SymfonyComponentDebugExceptionFatalErrorException]  
Call to a member function listens() on null

根据文档,它应该这样做:

该命令将生成列表中列出的任何事件或侦听器你的EventServiceProvider。已经存在的事件和侦听器将保持不变

我不明白我错过了什么,因为我没有找到任何类似的错误搜索网页

这是返回null的行:

$providers = $this->laravel->getProviders(EventServiceProvider::class);

因此,你的EventServiceProvider有一些问题…请试试这个:

<?php
namespace AppProviders;
use IlluminateSupportFacadesEvent;
use IlluminateAuthEventsRegistered;
use IlluminateAuthListenersSendEmailVerificationNotification;
use IlluminateFoundationSupportProvidersEventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'AppEventsFormBeforeCreate' => [
'AppListenersWebhookBeforeCreate',
],
'AppEventsFormAfterCreate' => [
'AppListenersNotifyAfterCreate',
'AppListenersWebhookAfterCreate',
],
'AppEventsFormBeforeUpdate' => [
'AppListenersWebhookBeforeUpdate',
],
'AppEventsFormAfterUpdate' => [
'AppListenersNotifyAfterUpdate',
'AppListenersWebhookAfterUpdate',
],
'AppEventsFormBeforeDelete' => [
'AppListenersWebhookBeforeDelete',
],
'AppEventsFormAfterDelete' => [
'AppListenersNotifyAfterDelete',
'AppListenersWebhookAfterDelete',
],
'AppEventsFormBeforeSave' => [
'AppListenersWebhookBeforeSave',
],
'AppEventsFormAfterSave' => [
'AppListenersNotifyAfterSave',
'AppListenersWebhookAfterSave',
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}

我的错,昨天晚上我好像真的很累,我们的项目是在Docker上运行的,我在Docker外部运行命令,而不是在Docker内部。

我不知道为什么它特别显示这个错误,但是一旦我在docker中运行命令,所有文件都正确生成。

相关内容

  • 没有找到相关文章

最新更新