How to call a function when a user logs into the backend?
Ad
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
Ad
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
Related Questions
Ad
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page
Ad