Laravel Fortify自定义身份验证重定向 [英] Laravel Fortify Customize Authentication Redirect

查看:94
本文介绍了Laravel Fortify自定义身份验证重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel加强自定义身份验证过程中,我无法重定向到带有错误消息的登录页面,而这是我们能够在Auth中完成的.这是自定义文档链接: https://jetstream.laravel.com/1.x/features/authentication.html#customizing-the-authentication-process

In Laravel fortify on customization authentication process, i can not able to redirect to login page with error message which we were able to do in Auth. Here is the customization documentation link: https://jetstream.laravel.com/1.x/features/authentication.html#customizing-the-authentication-process

        if ($user && Hash::check($request->password, $user->password) && $user->status == 'active') {
            return $user;
        } elseif ($user->status == 'inactive') {
            //redirect with some error message to login blade
        } elseif ($user->status == 'blocked') {
            //redirect with some error message to login blade
        }

请帮助我.

推荐答案

我了解您对文档的不满(或缺乏).我有一个类似的问题,这就是我设法做到的:

I understand your frustration with the documentation (or lack thereof). I had a similar problem and this is how I managed to do it:

if ($user && in_array($user->status_id, [1,2,3])) {
    if (Hash::check($request->password, $user->password)) {
        return $user;
    }
}
else {
    throw ValidationException::withMessages([
        Fortify::username() => "Username not found or account is inactive. Please check your username.",
    ]);
}

https://github.com/laravel/fortify/issues/94#issuecomment-700777994

这篇关于Laravel Fortify自定义身份验证重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆