3

By default the user is redirected to the dashboard. How can I change that so that the user is redirected to my plugins page?

dragontree
  • 1,709
  • 11
  • 14

2 Answers2

6

Backend controllers fire the backend.page.beforeDisplay event which we can listen to in our plugins boot() method and then redirect the user:

// listen for the display event of the Dashboard controller
Event::listen('backend.page.beforeDisplay', function($controller, $action){
    // redirect from dashboard to somewhere else
    if ($action == 'index' && $controller instanceof \Backend\Controllers\Index){
        return Backend::redirect('acme/plugin/somewhere');
    }
});

Additional conditions can of course be added.

dragontree
  • 1,709
  • 11
  • 14
-1

The first and easy approach is to remove the "View desktop" permission to that user or create a group without that permission.

Second.

You can hook the appropriated event on your plugin's boot method and make the redirect.

Event::listen('backend.user.login',function($user){
     return Backend::redirect('acme/yourplugin/controller/method');
});

PS. don't forget to set the $elevated=true on your plugin according to documentation October Docs - elevated permissions

OsDev
  • 1,243
  • 9
  • 20
  • When you remove the permission to view the dashboard, then the user is redirected to the next viewable page. You cannot specify which one – dragontree May 31 '17 at 06:28
  • You can, by defining the priority when registering pages in plugin.php. – Tschallacka May 31 '17 at 07:19
  • Did you test the redirect? The event is fired in the user model `afterLogin()` function and the return value is not processed. Therefore returning the redirect does nothing – dragontree Jun 07 '17 at 07:09