Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Deekshith's avatar

Add extra parameter or query string to socialite google signin

I am using laravel socialite


public function redirectToGoogle()
    {	
    	

       return Socialite::driver('google')->with(['redirect' => $redirect])->redirect();
    }


i tried to $request->all() for above response but not getting redirect value.

I want to add query string like redirectto?=http://localhost/project/checkout

so when user logs in with facebook based on redrect query string i should redirect the user.

0 likes
4 replies
gitwithravish's avatar

Why making it complicated when Socialite already provides you a dedicated way of doing such things ? :)

config/services.php

'facebook' => [
    'client_id' => env('FACEBOOK_CLIENT_ID'),
    'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
    'redirect' => 'http://your-callback-url',
],

Provide two routes

  • One for login
  • Other for callback
Route::get('login/google', [LoginController::class, 'redirectToProvider']);
Route::get('login/google/callback', [LoginController::class, 'handleProviderCallback']);
class LoginController extends Controller
{
    public function redirectToProvider()
    {
	return \Socialize::with('google')->redirect();
    }

    public function handleProviderCallback()
    {
	redirect()->rout('target-route')
    }
}

Docs

https://laravel.com/docs/8.x/socialite#routing

Deekshith's avatar

@gitwithravish i have already implemented this. my question is i want to change call back URL in two cases if user directly goes to login page then he will redirects to his profile page if he comes to login page during checkout then i should redirect him to checkout page instead of profile page so i am trying to fetch by passing optional parameter which has suggested in documentation but it is not working.

gitwithravish's avatar

@deekshith Ah, I see. In that case , because you can't simple use redirect->back(), you should use session variable.

Steps

  • Create a session variable redirectTo and save current route.
  • Redirect user to socialite login page
  • Once user entered right credentials and you need to redirect him to the original page, get the session('redirectTo') variable and redirect the user to that page !
  • And a good practice would be to delete that session variable as well. Make sense ?
2 likes

Please or to participate in this conversation.