Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Backend;
- use System\Classes\PluginBase; as PluginBase;
- use Event;
- use BackendAuth;
- use Session;
- use Illuminate\Support\Facades\Redirect;
- class Plugin extends PluginBase
- {
- public function boot()
- {
- // ......
- // save in session that need redirect
- // because in this event can't do redirect
- Event::listen('backend.user.login', function($model) {
- foreach (BackendAuth::getUser()->roles as $role) {
- if ($role->code === 'admin') { // for example redirect only for admins
- Session::put('redirectAfterLogin', '/backend/some/url');
- }
- }
- });
- Event::listen('backend.page.beforeDisplay', function($controller, $action, $params) {
- // .....
- if ($redirectAfterLogin = Session::pull('redirectAfterLogin', null)) {
- return Redirect::to($redirectAfterLogin); // do redirect
- }
- });
- // .....
- }
- }
Add Comment
Please, Sign In to add comment