[英]Laravel 8 “fortify” redirect not working after registration on production
I have setup a role base authentication for admin and users to be redirected to a different route after registration and login which perfectly well on my local machine but when I deploy to production, it redirects to /home which I have not declared in my web.php我已经为管理员和用户设置了角色基础身份验证,以便在注册和登录后重定向到不同的路由,这在我的本地机器上非常好,但是当我部署到生产时,它重定向到我没有在我的网络中声明的 /home。 php
FortifyServiceProvider.php FortifyServiceProvider.php
$this->app->singleton(
LoginResponseContract::class,
LoginResponse::class
);
$this->app->singleton(
TwoFactorLoginResponseContract::class,
TwoFactorLoginResponse::class
);
loginResponse.php登录响应.php
public function toResponse($request)
{
$role = \Auth::user()->role_id;
if ($request->wantsJson()) {
return response()->json(['two_factor' => false]);
}
$home = $role == 1 ? '/admin' : '/account';
return redirect()->intended($home);
}
RouteServiceProvider.php路由服务提供者.php
public const ACCOUNT = '/account';
public const ADMIN = '/admin';
CreateNewUser.php创建新用户.php
$user = User::create([
'name' => $input['name'],
'username' => $input['username'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'role_id' => 2,
'referrer_id' => $referrer->id ?? null,
]);
$user->notify(new WelcomeEmail($user));
return $user;
Please any help would be appreciated, I have been stuck for the past two days请提供任何帮助,我将不胜感激,过去两天我一直被困
thanks 🙏谢谢🙏
maybe the version of php of your local and production is different so some php version does not work with this form of IF use this way:也许您本地和生产的 php 版本不同,因此某些 php 版本不适用于这种形式的 IF 使用这种方式:
public function toResponse($request)
{
$role = \Auth::user()->role_id;
if ($request->wantsJson()) {
return response()->json(['two_factor' => false]);
}
if($role == 1){
$home = '/admin';
}else{
$home ='/account';
}
return redirect()->to($home);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.