简体   繁体   English

Laravel Octane 事件侦听器未触发

[英]Laravel Octane Event Listener not firing

I'm using laravel sail to run laravel octane on swoole.我正在使用 laravel sail 在 swoole 上运行 laravel octane。

I made a change to my EventServiceProvider:我对我的 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.我试过清除缓存、composer dump-autoload、php artisan optimize、重新加载 octane、停止 octane 并重新启动它。 Even stopping the docker containers and starting them again.甚至停止 docker 容器并重新启动它们。 Nothing works.什么都不管用。

It logs the list of listeners (including the CreateUserTeam listener) and it will fire the Email notification but not the other listener.它记录侦听器列表(包括 CreateUserTeam 侦听器),它会触发 Email 通知,但不会触发其他侦听器。

If anyone has any insight... please.如果有人有任何见解......请。 I am at wits-end我无计可施

I created same situation with you,我和你创造了同样的情况,

Added my listener like you did:像你一样添加了我的听众:

    protected $listen = [
    Registered::class => [
        SendEmailVerificationNotification::class,
        TestListener::class,
    ],
];

Used Laravel's registration test for it:使用 Laravel 的注册测试:

<?php

namespace Tests\Feature\Auth;

use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class RegistrationTest extends TestCase
{
    use RefreshDatabase;

    public function test_registration_screen_can_be_rendered()
    {
        $response = $this->get('/register');

        $response->assertStatus(200);
    }

    public function test_new_users_can_register()
    {
        $response = $this->post('/register', [
            'name' => 'Test User',
            'email' => 'test@example.com',
            'password' => 'password',
            'password_confirmation' => 'password',
        ]);

        $this->assertAuthenticated();
        $response->assertRedirect(RouteServiceProvider::HOME);
    }
}

Here is my test listener这是我的测试听众

<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Registered;

class TestListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        \Log::debug("HIT");
        dump("test");
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(Registered $event)
    {
        $user = $event->user;

        dump($user->id);
    }
}

And run my test inside the sail:并在帆内运行我的测试:

帆输出

As you can see it runs handle function inside TestListener.php如您所见,它在 TestListener.php 中运行句柄 function

Can you remove you other code parts inside handle function and try like this?您可以删除句柄 function 中的其他代码部分并尝试这样吗? I think you may have some error in your code我想你的代码可能有一些错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM