Laravel 9 Separated custom login page redirect to multiple page

Viewed 22

This is Tanbhir Hossain. i am trying to develop custom separated login and registration for mobile and pc version from same users table.

if user login from mobile version which is /mobile/login then it's redirect to mobile dashboard which is /mobile/index.

if the user login from pc version which is /login then it's redirect to pc version which is /home

I am trying to redirect by this on RedirectIfAuthenticated file. there i just use a extra const MOBILE = /mobile/index

and trying to get request from login page by value of 0000 but it's not working

public function handle(Request $request, Closure $next, ...$guards)
    {
        $guards = empty($guards) ? [null] : $guards;

        foreach ($guards as $guard) {
            if (Auth::guard($guard)->check()) {
                //return redirect(RouteServiceProvider::HOME);
               if ($request->aaaa == 0000)
               {
                //return redirect()->route('mobile.index');
                return redirect(RouteServiceProvider::MOBILE);
               }
               else {
                return redirect(RouteServiceProvider::HOME);
               }
            }
        }

        return $next($request);
       // return redirect()->back();
    }

Please help me to develop this. Thanks in advance

1 Answers

From Laravel official documentation you can check the current request like this

if ($request->is('admin/*')) {
    //
}

in your case it could be something like

if ($request->is('mobile/login')) {
    // redirect to /mobile/index
} else {
    // redirect to normal index
}
 
Related