Čamo
1 month ago
261
3
General

Laravel 5.8 redirect()->route('name') not working

Posted 1 month ago by Čamo

I have controller which should redirect to another route. Simple as redirect()->route('name'). But if the redirect() is not in the main action method Laravel does not redirect me. If redirect() is in the main action method it works well.

Look at the code:

public function callback()
{
	$gitHubUser = Socialite::driver('github')->user();

	$user = \App\User::where(['email' => $gitHubUser->getEmail(), 'social_network' => self::DRIVER])->first();

	$user = $user ?: $this->createUser($gitHubUser);

	$this->loginAndRedirect($user);
		
        //return redirect()->route('book.index');  // This works fine
}


private function loginAndRedirect(\App\User $user)
{
	Auth::login($user);
	flash('You were successfully logged in.', 'success');
               
       return redirect()->route('book.index');  // This does not work.
}

I dont understand it. 

Please sign in or create an account to participate in this conversation.