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

vrkansagara's avatar

How to get Socialite Dynamic driver name ?

I want driver name from request payload. like github, twitter or facebook, etc. The current problem is that I have to explicitly provide a driver name.

public function handleProviderCallback(Request $request)
{
    try {
        $user = Socialite::driver('github')->user();
        return redirect()->route('dashboard');
    } catch (\Exception $exception) {
        return $exception;
    }
}
0 likes
1 reply
Oussama.tn's avatar

Hi @vrkansagara, try this:

// Inside your routes file:

Route::get('{driver}/callback', 'Auth\LoginController@handleProviderCallback')
    ->name('login.callback');


// Inside your login controller

public function handleProviderCallback($driver)
{
    try {
        $user = Socialite::driver($driver)->user();
        return redirect()->route('dashboard');
    } catch (\Exception $exception) {
        return $exception;
    }
}

Please or to participate in this conversation.