WildsideUK / Laravel-Userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created_by` and `updated_by` columns on your model, populated by the currently authenticated user in your application.
https://wildside.uk
MIT License
570 stars 64 forks source link

It's not possible to define another 'creating' listener on 'userstamp' model #16

Closed shanginn closed 6 years ago

shanginn commented 6 years ago

Hello there! Great extension, thank you 👍 But I think there is a problem. After applying Usersstamps trait one can no longer define his own creating (and I think updating as well) listeners.

For example, I have model

...
class Blabla extends Model
{
  use Userstamps;
}

and Observer

...
class BlablaObserver
{
  public function creating(Blabla $bla)
  {
     dd($bla);
  }
}

and Blabla::observe(BlablaObserver::class); in AppServiceProvider.

and creating is never fired in my observer; but saving for example is firing.

I think this is due to the fact you redefine creating function in yours registerListeners() function like this: static::creating('Wildside\Userstamps\Listeners\Creating@handle');

Am I right, or am I do something wrong?

mattmcdonald-uk commented 6 years ago

I believe your own observers should continue to fire.

With the trait removed does your observer work as expected?

Can you confirm which Laravel version you're using?

shanginn commented 6 years ago

I'm sorry, you right. I have my own trait with another observer in parent class. I guess they conflicting. Thank you and sorry again.