【发布时间】:2018-07-19 11:14:55
【问题描述】:
我想监听由包 (Laravel impersonate) 触发的事件。
当我像这样设置我的 EventServiceProvider 时:
<?php
namespace App\Providers;
use App\Listeners\LogImpersonation;
use Illuminate\Support\Facades\Event;
use Lab404\Impersonate\Events\TakeImpersonation;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
TakeImpersonation::class => [
LogImpersonation::class,
]
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}
我收到以下错误:
传递给 App\Listeners\LogImpersonation::handle() 的参数 1 必须是 App\Events\TakeImpersonation 的一个实例, Lab404\Impersonate\Events\TakeImpersonation given
我的日志模拟:
<?php
namespace App\Listeners;
use App\Events\TakeImpersonation;
use App\User;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
class LogImpersonation
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param TakeImpersonation $event
* @return void
*/
public function handle(TakeImpersonation $event)
{
Log::info($event->impersonator->name . ' ingelogd als ' . $event->impersonated);
}
}
我无法想象我必须移动事件,这是我第一次尝试使用事件,所以我一定错过了一些简单的东西。
【问题讨论】:
标签: php laravel events listener