whats the correct way to listen to an event in a package in laravel ?
Inside the package service provider class StudentServiceServiceProvider extends ServiceProvider I have this
protected $listen = [
        \Illuminate\Auth\Events\Login::class => [
            MyListener::class,
        ],
    ];
what am i missing?
The $listen mapping is only used to register listeners at an app-level inside App\Providers\EventServiceProvider, not within a package's ServiceProvider.
The proper way to register an event listener from within a package's ServiceProvier in my opinion is to simply use the Event facade in it's boot function.
So in OP's case that would be:
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        \Illuminate\Support\Facades\Event::listen(
            \Illuminate\Auth\Events\Login::class,
            MyListener::class
        );
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With