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

Kris01's avatar

Laravel Socialite

Hello Guys,

I am using laravel socialite to login a user with paypal, and when I try to add aditional dynamic parameters I can't access them in my callback

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

and when in my callback function/method I can't access that 'listing_id' parameter.

How can I solve this problem?

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

You are passing the listing_id to the PayPal OAuth endpoint; but where are you trying to access it? If you intend to use it in your callback endpoint, then you are depending on PayPal to forward these query params, which I expect it does not.

Instead, you could use the Session to store the listing_id and inside the callback endpoint (which authenticates the User), redirect according to the listing URL:

session(['listing_id' => $listing_id]);
return Socialite::driver('paypal_sandbox')->redirect();
Route::get('/auth/callback', function () {
    $user = Socialite::driver('paypal_sandbox')->user();
    Auth::login($user);
 
    $redirectUrl = session()->has('listing_id')
        ? route('listings.show', session('listing_id'))
        :  route('dashboard');

    return redirect($redirectUrl);
});

Please or to participate in this conversation.