Laravel 5.8 Login with Google Account Example
https://www.itsolutionstuff.com/post/laravel-58-login-with-google-account-exampleexample.html
Laravel 5.8 Login with Google Account Example
By Hardik Savani May 27, 2019 Category : PHP LaravelPauseUnmuteLoaded: 1.85%Fullscreen
In this tutorial, i would like to share with you how to login with google account using socialite package in laravel 5.8 app. we can easily sign in and signup with google gmail account in laravel 5.8. we will use google authentication for login in laravel 5.8.
If you want to create login with google account then you can do it easily using laravel socialite composer package. If you use other php framework then it difficult to make login with google. But laravel provide socialite so you can so it quickly. You just need to create secret, app id from google api console.
Just follow few steps to done login with google account example:
Preview:

Step 1: Install Laravel 5.8
In this step, if you haven't laravel 5.8 application setup then we have to get fresh laravel 5.8 application. So run bellow command and get clean fresh laravel 5.8 application.
Step 2: Install Socialite
In first step we will install Socialite Package that provide fb api to connect with google account. So, first open your terminal and run bellow command:
After install above package we should add providers and aliases in config file, Now open config/app.php file and add service provider and aliase.
Read Also: Laravel 5.8 CRUD (Create Read Update Delete) Tutorial For Beginners
Step 3: Create Google App
In this step we need google client id and secret that way we can get information of other user. so if you don't have google app account then you can create from here : Google Developers Console. you can find bellow screen :

Now you have to click on Credentials and choose first option oAuth and click Create new Client ID button. now you can see following slide:

after create account you can copy client id and secret.
Now you have to set app id, secret and call back url in config file so open config/services.php and set id and secret this way:
config/services.php
Step 4: Add Database Column
In this step first we have to create migration for add google_id in your user table. So let's run bellow command:
Migration
Update mode like this way:
app/User.php
Step 5: Create Routes
After adding google_id column first we have to add new route for google login. so let's add bellow route in routes.php file.
app/Http/routes.php
Step 6: Update Controller File
After add route, we need to add method of google auth that method will handle google callback url and etc, first put bellow code on your LoginController.php file.
app/Http/Controllers/Auth/LoginController.php
Step 7: Create Blade File
Ok, now at last we need to add blade view so first create new file googleAuth.blade.php file and put bellow code:
resources/views/googleAuth.blade.php
Read Also: Import and Export CSV file in Laravel 5.8
Ok, now you are ready to use open your browser and check here : URL + '/google'.
I hope it can help you...
Video
Last updated
Was this helpful?

