php - 无法重定向到 Laravel 5.2 中的路径

标签 php laravel authentication

在 Laravel 5.1 中,我覆盖了 postRegister,然后将其重定向到一个路径,它运行良好,但在 Laravel 5.2 中,我编写了相同的代码,但它不起作用。这是我的一些代码

public function postRegister(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException(
                $request, $validator
            );
        }

        $this->create($request->all());

        return redirect('login');
    }

我想在用户注册后重定向到页面登录。

我遇到这样的问题:

ErrorException in SessionGuard.php line 411: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given

注意:我使用的是laravel默认的脚手架

提前致谢

最佳答案

postRegister() 不再是要覆盖的方法。改用这个:

public function register(Request $request)
{
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    Auth::guard($this->getGuard())->login($this->create($request->all()));

    return redirect(route('route.after.register'));
}

不要忘记导入 Auth Facade:

use Illuminate\Support\Facades\Auth;

关于php - 无法重定向到 Laravel 5.2 中的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34606059/

相关文章:

php - 为什么从 PHP 调用的长时间运行的 Python 脚本会失败

php - 为 Laravel 路由添加 url 扩展

c# - 如何配置部署在 IIS 和远程客户端上的 WCF 服务以从远程客户端 PC 进行身份验证?

php - 通过 PHP SDK 的 S3 客户端初始化错误

php - mysql unhex() 不能在 linux 服务器上运行?

php - 如果用户在 php 中空闲,如何注销 session

php - 意外 token '<' - AJAX

php - Maatwebsite/Excel导出错误

php - 验证密码 yii 框架

ios - 如何在 Swift (iOS) 中保持用户登录状态?