Create redirect after registration Laravel

流过昼夜 提交于 2021-01-28 11:26:22

问题


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. After successful registration, I should be thrown to successfull.blade.php Please help me.

RegistersUsers.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

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


回答1:


Routes: define a new function in HomeController named as success and call success.blade.php inside function.

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

RegisterController

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

RegistersUsers.php

after user account created successfully

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

Hope it will help you :)



来源:https://stackoverflow.com/questions/60145365/create-redirect-after-registration-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!