Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lumen: EventListeners not called/registered #119

Closed
kbleeck opened this issue Aug 26, 2020 · 2 comments
Closed

Lumen: EventListeners not called/registered #119

kbleeck opened this issue Aug 26, 2020 · 2 comments
Assignees

Comments

@kbleeck
Copy link

kbleeck commented Aug 26, 2020

  • Laravel version: Lumen 7.x
  • Laravel Soft Cascade Version: 7.0.1
  • PHP Version: 7.4
  • Database Driver & Version:

Description:

In Lumen 7.x, the Event Listeners in LumenEventServiceProvider are not properly registered and thus not called on delete.
The boot() Method in Providers/LumenEventServiceProvider is never called by the framework and thus the event listeners are not properly registered.

Steps To Reproduce:

  1. Set up laravel-soft-cascade in a fresh lumen 7.x project
  2. create models and add SoftCascadeTrait, $softCascade and relations
  3. delete parent model
  4. children are not soft-deleted

How to Fix:

In Providers/LumenServiceProvider: simply moving $this->app->register(LumenEventServiceProvider::class); from boot() to register():

// src\Providers\LumenServiceProvider.php
<?php

namespace Askedio\SoftCascade\Providers;

use Illuminate\Support\ServiceProvider;

class LumenServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->register(LumenEventServiceProvider::class); // move this here
    }

    /**
     * Register routes, translations, views and publishers.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}
@maguilar92
Copy link
Collaborator

@kbleeck Following laravel documentation is in the correct site.

https://lumen.laravel.com/docs/7.x/providers#writing-service-providers

As mentioned in docs the boot method "This method is called after all other service providers have been registered".

@Oranzh
Copy link

Oranzh commented Aug 9, 2021

I also encountered this problem, and how do u solve that, thanks @kbleeck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants