//redirect public function socialLogin() { return Socialite::driver('facebook')->redirect(); } //callback public function handleProviderCallback() { try { $user = Socialite::driver('facebook')->user(); $finduser = User::where('facebook_id', $user->id)->first(); if($finduser){ Auth::login($finduser); return redirect()->intended('/'); }else{ $newUser = User::create([ 'name' => $user->name, 'email' => $user->email, 'facebook_id'=> $user->id, 'password' => encrypt('Test123456') ]); Auth::login($newUser); return redirect()->intended('/'); } } catch (Exception $e) { dd($e->getMessage()); } } //routes Route::get('/login/facebook',[login::class,'socialLogin'])->name('redirectToFacebook'); Route::get('/login/facebook/callback',[login::class,'handleProviderCallback'])->name('callbackFacebook'); // config/services.php 'facebook' => [ 'client_id' => '', //Facebook API 'client_secret' => '', //Facebook Secret 'redirect' => '',//callback url ], //config/app.php 'Socialite' => Laravel\Socialite\Facades\Socialite::class, //aliases Laravel\Socialite\SocialiteServiceProvider::class, //providers
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter