Php Laravel 5.3注册后重定向用户

Php Laravel 5.3注册后重定向用户,php,laravel-5,Php,Laravel 5,我正在使用Laravel5.3和php artisan命令make:auth构建注册和登录的框架。用户注册后,我想将他重定向到一个页面,上面写着“验证您的电子邮件”,我不希望它像默认设置那样自动登录用户 我只能想到,在RegisterController的create()方法中,我想重定向到另一个视图,而不是返回用户(我假设它自动登录的位置) protected function create(array $data) { $confirmation_code = str_random(

我正在使用Laravel5.3和php artisan命令
make:auth
构建注册和登录的框架。用户注册后,我想将他重定向到一个页面,上面写着“验证您的电子邮件”,我不希望它像默认设置那样自动登录用户

我只能想到,在RegisterController的
create()
方法中,我想重定向到另一个视图,而不是返回用户(我假设它自动登录的位置)

protected function create(array $data)
{
    $confirmation_code = str_random(30);

    Mail::to($data['email'])->send(new Company($confirmation_code));

    User::create([
        'confirmation_code' => $confirmation_code,
        'password' => bcrypt($data['password']),
        'email' => $data['email']
    ]);

    return redirect()->route('verifyemail');
}
但是我得到了这个错误:
参数1传递给Illumb\Auth\SessionGuard::login()必须实现接口Illumb\Contracts\Auth\Authenticatable,Illumb\Http\RedirectResponse的实例,在第32行的C:\xampp\htdocs\app\vendor\larvel\framework\src\illumb\Foundation\Auth\RegisterUsers.php中调用,并定义了

我试图覆盖RegistersUsers.php中的
register(Request$Request)
方法,以删除进行登录的行,但它仍然不起作用。
有什么想法吗


编辑:我添加了
$this->guard()->logout()
在登录后被重写的
register
方法。它可以工作,但这不是正确的方法,我想找到另一种解决方案。

我会创建您自己的寄存器控制器以获得更大的灵活性。在他们的示例中,使用create/store方法创建并重定向到您想要的位置。不会花费太长时间

在app/Http/Controllers/Auth/RegisterController中,在方法创建后添加以下内容:

在这里输入代码

public function redirectPatch() 
{
  return "verifyemail";
} 
示例

protected function create(array $data)
{
    $confirmation_code = str_random(30);

    Mail::to($data['email'])->send(new Company($confirmation_code));

    User::create([
        'confirmation_code' => $confirmation_code,
        'password' => bcrypt($data['password']),
        'email' => $data['email']
    ]);

}
public function redirectPatch() 
{
  return "/verifyemail";
} 

几个星期以来,我一直在努力寻找解决办法。 要在注册后覆盖默认URL,只需在create函数中添加以下内容:

$this->redirectTo = '/url-after-register';
就这样

protected function create(array $data) {
    $this->redirectTo = '/url-after-register';

    return User::create([...]);
}

谢谢!我已经实施了你的解决方案。或者您可以重写类中已注册的方法并重定向到特定路由

protected function registered(Request $request, $user)
{
    $this->guard()->logout();
    return Redirect::route('your.route');
}

在RegisterController.php中使用这些方法

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

    event(new Registered($user = $this->create($request->all())));

    Mail::to($user->email)->send(new ConfirmationEmail($user));

    return back()->with('status', 'Thanks for signing up! Please check your email.');
}

public function confirmEmail($confirmation_code)
{
  User::whereConfirmationCode($confirmation_code)->firstOrFail()->hasVerified();
  return redirect('login')->with('status', 'You have successfully verified your account. Please Login.');
}

这听起来像是一个不必要的解决办法。。必须有一个更简单的方法。