lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 124 forks source link

`asListener` does not trigger when registered in model class #183

Closed leo-unglaub closed 1 month ago

leo-unglaub commented 2 years ago

Hey, the asListener method is not called when the action is registered in the model file itself:

// app/Models/Foobar.php
protected $dispatchesEvents = [
  'created' => MyCreatedAction::class,
  'saving' => MySavingAction::class,
];

The __construct method is called on both actions, but not the asListener or the handle method. Any ideas why? Is this a bug or a feature?

Thanks Leo

austincarpenter commented 2 years ago

That will dispatch an event with the name MyCreatedAction. Instead do something like:

protected static function booted()
{
    static::created(function (self $foobar) {
        MyCreatedAction::run($foobar);
    });
}

to simply run the action.

vpratfr commented 1 year ago

@leo-unglaub @lorisleiva This issue could be closed

Wulfheart commented 1 month ago

Closing due to inactivity. If you feel your issue is still relevant please open a new one with a link to a repository containing a minimal reproducible example.