Tuesday, May 23, 2017

How to redirect user in profile dependency of type?

I have some types of users. How to redirect user to profile dependency of account type?

After succesfull authorization I need to check Auth::user()->type and redirect to specified controller url.

I tried to use middleware for that:

class RedirectIfAuthenticated
{
    /**
     * Handle an 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::guard($guard)->check()) {

            if(Auth::user()->type == "1"){
                return redirect('/center');
            }

           if(Auth::user()->type == "2"){
               return redirect('/doctor');
           }
        }

        return $next($request);
    }
}

But where to call this middleware once?



via Blablacar

Advertisement