Ad

How To Call A Function When A User Logs Into The Backend?

- 1 answer

I need to set some session variables when the user logs into the backend. A logical choice would be to listen for the backend.user.login event in my plugins boot() method, but for some reason it does not work (no sure if it is supposed to)

    Event::listen('backend.user.login', function($user) {
        # do something
    });

So the question is, how can I execute some code when the user logs in?

Ad

Answer

Hello this feature it's a hidden trick but you have to set the $elevated property true.

class Plugin extends PluginBase
{

    public $elevated = true; //this thing :D
    public function boot()
    {
        Event::listen('backend.user.login', function ($user) {
            \Log::info('now WORKS :D');
        });
    }
}

It's seems that to be able to listen backend events it's an elevated privilege

/** * @var boolean Determine if this plugin should have elevated privileges. */

Ad
source: stackoverflow.com
Ad