Laravel 9分离的自定义登录页面重定向到多个页面



我是Tanbhir Hossain。我正在尝试从相同的用户表中为移动和pc版本开发自定义的独立登录和注册。

如果用户从移动版/mobile/login登录,则重定向到移动仪表板/mobile/index。

如果用户从/login的pc版本登录,则重定向到/home 的pc版本

我正在RedirectIfAuthenticated文件上尝试通过此重定向。在那里,我只使用了一个额外的常量MOBILE=/MOBILE/index

并尝试从登录页面获取值为0000的请求但不起作用

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();
}

请帮我发展一下。提前感谢

从Laravel官方文档中,您可以检查当前的请求,如以下

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

在你的情况下,它可能是类似的东西

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

最新更新