简体   繁体   English

注册 Laravel 后创建重定向

[英]Create redirect after registration Laravel

I want after successful registration I was redirected to successfull.blade.php , but for some reason it either gives a 404 error, that the page was not found, or that it always throws me to home ... I can't handle it please help me.我想在成功注册后我被重定向到successfull.blade.php ,但由于某种原因,它要么给出 404 错误,要么找不到页面,要么总是把我扔回家......我无法处理它请帮我。 After successful registration, I should be thrown to successfull.blade.php Please help me.注册成功后,我应该被抛出到successfull.blade.php请帮帮我。

RegistersUsers.php注册用户.php

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

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

      $this->guard()->login($user);

      return $this->registered($request, $user)
      ?: redirect()->to('/successfull');
}

RegisterController注册控制器

protected function redirectPath()
{
  if (Auth::user()->role_id==NULL) {
    return '/successfull';
  } else {
    return '/successfull';
  }
}

web.php网页.php

Auth::routes();

Route::get('/home', 'HomeController@getUser')->name('users');

Route::get('/successfull', 'Auth\RegisterController@redirectPath');

homecontroller家庭控制器

public function getUser(){

        $user=auth()->user();
         return view('home',[
                'users' =>  $user,
            ]);
}

throws me to home because of homecontroller , but I want it to be only after login, and after registration I need to be redirected to another file由于homecontroller将我扔home ,但我希望它仅在登录后才能使用,并且在注册后我需要重定向到另一个文件

Routes: define a new function in HomeController named as success and call success.blade.php inside function.路由:HomeController define一个名为success的新function ,并在函数内部调用success.blade.php

Route::get('/successfull', 'HomeController@success');

RegisterController注册控制器

if (Auth::user()->role_id != NULL) {
  return redirect('/successfull');
}

RegistersUsers.php注册用户.php

after user account created successfully用户账户创建成功后

redirect('/successfull')->withSuccess(' Account Created Successfully');

Hope it will help you :)希望它会帮助你:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM