1
votes

I was following the laravel 5.6 documentation and according to them changing $redirectTo variable inside Register Controllers should redirect user to desired location but I always get redirected to '/home'.

RegisterController

protected $redirectTo = '/home';
protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'username' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }

web.php

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');
1
which route you want to redirect and which laravel version you are usingShahrukh
Which Version of laravel are you using?Malkhazi Dartsmelidze
Is the registration successful or is there a validation error?apokryfos
Check the db, you successfully registered or notsta
As per your sample code your are not changing the $redictTo variable. Also try return redirect('your/desired/location');Susantha

1 Answers

1
votes

In RegisterController

public function register(Request $request)
    {
        $this->validator($request->all())->validate();
        event(new Registered($user = $this->create($request->all())));
        return redirect(route('register'));
    }



 protected function registered(Request $request, $user)
    {
        Auth::logout();
        return redirect(route('register'));
    }

In LoginController,

    protected $username; //username
    
     public function __construct()
        {
            $this->middleware('guest')->except('logout');
            $this->username=$this->findUsername(); 
        }
    
         public function username()
            {
                return $this->username;
            }



public function findUsername()
    {
        $login     = \request()->input('login');
        $fieldType = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
        \request()->merge([$fieldType => $login]);
        return $fieldType;
    }


  protected function authenticated(Request $request, $user)
    {
        if($user->status==0)
        {
            Auth::logout();
            return redirect()->route('login');
        }
    }