This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

kent2894
kent2894

I am working on creating a client specific member plugin that extends User. Using the documentation at http://octobercms.com/docs/plugin/events, I am trying to listen for the "user.register" event. I can't see the event being fired, but am able to see that my code is running before and after the lines of code where I am listening.

My plugin boot() method:

public function boot()
{
    Event::listen('rainlab.user.register', function($user){
        die( "Registered U"); // die here just to verify that I can catch the event
    });
}

Has anyone else been able to extend User like this? I can't see where the event is fired in code.

Last updated

kent2894
kent2894

Do I need to add the code to fire the event myself?

that0n3guy
that0n3guy

I've not messed with this much, but have a look at http://culttt.com/2014/03/10/using-events-laravel-4/

That article say there are some "core" laravel events, you can see a list here: http://jasonlewis.me/article/laravel-events

You might be able to use the user saved event... I'm just guessing since I've not tested this yet.

kent2894
kent2894

Thanks for the suggestion. I think my issue was that I took the documentation literally (it specifically says to look for the user.register event).

It seems that hooking in the the eloquent user creation might be the key for me.

Reboot
Reboot

Running into an issue with this myself now, Kent2894 did you find the proper event to hook into?

It would be nice if there was a list of all possible events to hook into. I've tried doing a global search in my IDE for Event::fire, but that only turns up a handful of events, none of which reference anything to do with the User model.

kent2894
kent2894

Did not find anything. I went through the same steps... searched the entire code base for events being fired.... and found only unrelated events. Assumed that there are some events being fired automatically that are hard to find in code, and did not really find any.

I am reluctant to muck around in the original RainLab.User plugin... but I think I am going to have to if only to put in the firing of a few events (register and update I'm thinking).

Reboot
Reboot

Yeah I feel the same, I'd rather not inject code into anything outside my plugin, app or theme files. I'll keep digging, if I find anything I'll post it here.

kent2894
kent2894

I just did a trace on all events being fired. The event that seems most promising is: "eloquent.created: RainLab\User\Models\User"

There are a few others created by eloquent that seem useful, but this seems like it should be fired once the user record is added to the db.

Reboot
Reboot

How did you run a trace on all events being fired, did you use a specific logging tool or is this a feature built into laravel/OctoberCMS?

kent2894
kent2894

just a quick hack... had to provide default values for a few params in case there were multiple sent in (3 seemed like a good starting point). just output the event names to the screen.

public function boot()
{
    Event::listen('*', function($o1 = null, $o2 = null, $o3 = null ){

                    echo( "<br/>" . Event::firing() );

    });
}

Last updated

tsaunders836827
tsaunders836827

I know this is old, but I came across the same issue. You can use the following to listen for Rainlab User updating/saving events:


Event::listen('eloquent.updating: RainLab\User\Models\User', function(){
});

Last updated

Sandip Shinde
Sandip Shinde

Hello,

Is there a way to listen to Rainlab User sign-in and sign-out event?

Also, I wanted to listen to Backend user sign-in and sign-out event?

Please help, thanks!

jacqui15846
jacqui15846

I was looking at adding an avatar upon registration and did it this way: \Event::listen('eloquent.created: RainLab\User\Models\User', function($user){ $user->commitDeferred(post('_session_key')); });

Last updated

1-13 of 13

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.