Laravel Octane 事件监听器未触发
我正在使用 laravel sail 在 swoole 上运行 laravel Octane。
我对我的 EventServiceProvider 进行了更改:
<?php
namespace App\Providers;
use App\Events\SubscriptionCreated;
use App\Listeners\CreateUserTeam;
use App\Listeners\SendSubscriptionReceipt;
use App\Listeners\UpdateTeamFeatures;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
CreateUserTeam::class
],
SubscriptionCreated::class => [
SendSubscriptionReceipt::class,
UpdateTeamFeatures::class
]
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
\Log::debug("HERE", $this->listen);
}
}
这是我的侦听器:
<?php
namespace App\Listeners;
use App\Models\Team;
use Illuminate\Auth\Events\Registered;
class CreateUserTeam
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
\Log::debug("HIT");
}
/**
* Handle the event.
*
* @param Registered $event
* @return void
*/
public function handle(Registered $event)
{
$user = $event->user;
$team = Team::create([
'manager_id' => $user->id,
]);
$team->createAsStripeCustomer();
$user->update(['team_id' => $team->id]);
}
}
无论我尝试什么,这个事件侦听器都不会被触发。我尝试过清除缓存、composer dump-autoload、php artisan optimization、重新加载辛烷、停止辛烷并再次启动。甚至停止 docker 容器并重新启动它们。什么都不起作用。
它记录侦听器列表(包括 CreateUserTeam 侦听器),并且将触发电子邮件通知,但不会触发其他侦听器。
如果有人有任何见解......请。我束手无策
I'm using laravel sail to run laravel octane on swoole.
I made a change to my EventServiceProvider:
<?php
namespace App\Providers;
use App\Events\SubscriptionCreated;
use App\Listeners\CreateUserTeam;
use App\Listeners\SendSubscriptionReceipt;
use App\Listeners\UpdateTeamFeatures;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
CreateUserTeam::class
],
SubscriptionCreated::class => [
SendSubscriptionReceipt::class,
UpdateTeamFeatures::class
]
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
\Log::debug("HERE", $this->listen);
}
}
Here is my listener:
<?php
namespace App\Listeners;
use App\Models\Team;
use Illuminate\Auth\Events\Registered;
class CreateUserTeam
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
\Log::debug("HIT");
}
/**
* Handle the event.
*
* @param Registered $event
* @return void
*/
public function handle(Registered $event)
{
$user = $event->user;
$team = Team::create([
'manager_id' => $user->id,
]);
$team->createAsStripeCustomer();
$user->update(['team_id' => $team->id]);
}
}
No matter what I try this event listener is not being fired. I've tried clearing the cache, composer dump-autoload, php artisan optimize, reloading octane, stopping octane and starting it again. Even stopping the docker containers and starting them again. Nothing works.
It logs the list of listeners (including the CreateUserTeam listener) and it will fire the Email notification but not the other listener.
If anyone has any insight... please. I am at wits-end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我和你创建了同样的情况,
像你一样添加了我的监听器:
使用 Laravel 的注册测试:
这是我的测试监听器
并在帆内运行我的测试:
如您所见,它在 TestListener 内运行句柄函数.php
你可以吗删除句柄函数中的其他代码部分并尝试这样?我认为你的代码中可能有一些错误
I created same situation with you,
Added my listener like you did:
Used Laravel's registration test for it:
Here is my test listener
And run my test inside the sail:
As you can see it runs handle function inside TestListener.php
Can you remove you other code parts inside handle function and try like this? I think you may have some error in your code