Php Laravel添加了新的事件和侦听器don';行不通
更新Php Laravel添加了新的事件和侦听器don';行不通,php,laravel-5.6,Php,Laravel 5.6,更新$listen变量后 protected $listen = [ 'App\Events\UserActivationCode' => [ 'App\Listeners\UserActivationCode\SendMailNotification', 'App\Listeners\UserActivationCode\SendSMSNotification', ] ]; 在EventServiceProvider中运行 php art
$listen
变量后
protected $listen = [
'App\Events\UserActivationCode' => [
'App\Listeners\UserActivationCode\SendMailNotification',
'App\Listeners\UserActivationCode\SendSMSNotification',
]
];
在EventServiceProvider
中运行
php artisan event:generate
命令、事件和侦听器都已创建,我在过去部署了它们,现在将其更新为:
protected $listen = [
'App\Events\UserActivationCode' => [
'App\Listeners\UserActivationCode\SendMailNotification',
'App\Listeners\UserActivationCode\SendSMSNotification',
],
[
'App\Events\UserTracker' => [
'App\Listeners\UserTracker\StoreUserTracker',
]
]
];
然后再次运行命令,此事件和侦听器不创建,尽管我必须在Events
和Listeners
文件夹中手动创建此类,但现在此事件不适用于我
途中测试:
Route::get('/page/mahdi', function () {
event(new \App\Events\UserTracker(\App\User::find(2),'hi',request()->ip()));
}
活动:
class UserTracker
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
public $action_name;
public $user_ip;
public function __construct(User $user, $action_name, $user_ip)
{
$this->user = $user;
$this->action_name = $action_name;
$this->user_ip = $user_ip;
}
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
听众:
use App\Events\UserTracker;
class StoreUserTracker
{
public function __construct()
{
//
}
public function handle(UserTracker $event)
{
dd($event);
}
}
你的方括号太多了。删除
UserTracker
事件周围的内容:
protected $listen = [
'App\Events\UserActivationCode' => [
'App\Listeners\UserActivationCode\SendMailNotification',
'App\Listeners\UserActivationCode\SendSMSNotification',
],
'App\Events\UserTracker' => [
'App\Listeners\UserTracker\StoreUserTracker',
],
];