php - Multiple dynamic url redirect in Laravel -


i have looked @ many similar questions bu don't approach real problem. redirect user url after login depending on condition user.

i know can archieved middleware have tried in app\http\middleware\redirectifauthenticated.php

class redirectifauthenticated {     /**      * handle incoming request.      *      * @param  \illuminate\http\request  $request      * @param  \closure  $next      * @param  string|null  $guard      * @return mixed      */     public function handle($request, closure $next, $guard = null)     {         if (auth::user()->check()) {             $redirect = '/client';             if (auth::user()->hasrole('admin')){                 $redirect = '/admin';             }             return redirect($redirect);         }         return $next($request);     } } 

i realise not work after login. i'd redirect user depending whether he/she admin or client. know use: protected $redirectpath = '/url/to/redirect'; have multiple pages redirect to.

what best way this?

you over-write redirect method offered trait in app/http/controllers/auth/authcontroller.php

public function redirectpath() {     if (auth::user()->hasrole('admin')){         return '/admin';     }      return '/client'; } 

put in authcontroller.php.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -