Skip to content
Experts PHP
  • Web Tutorial Exercise
  • LARAVEL FRAMEWORK TUTORIAL
  • PYTHON TUTORIAL
  • LARAVEL 5.8
  • PHP TUTORIAL
  • HTML TUTORIAL
  • Mysql
  • C PROGRAM
  • PHP PROGRAM
Posted on March 20, 2019March 22, 2019 by jyoti

Login with Google in Laravel 5.7 Or Laravel 5.8 using Socialite Package

Laravel 5.8 Login with Google Using Socialite Package, Login with Google Laravel 5.8, Login with Google in Laravel 5.8 using Socialite Package

Hi Friends Today, I will tell you through this tutorial how you can login to the Laravel 5.7 Or Laravel 5.8 Framework by Google Plus Social Media Website.

Friends Laravel has a very power full Framework. In today’s day more developer is using the Laravel Framework. Because most functinality is already inbuilt in this framework. We just have to manage it by command. So we were talking that in google plus laravel 5.7 Or Laravel 5.8 How to login.

So Friends, I would like to tell you that Laravel has given a package of itself. The name of this is socialite package. By installing this package in our application, we can easily login from Google Plus. So let’s go, we will tell you step by step and together you will also explain the step of installetion.

Step 1: Make a project of Laravel 5.7 Or Laravel 5.8 Google Plus Login.
Step 2: Then create users table with column.
Step 3: Install Socialite Package For Google Plus
Step 4: add service provider and alias.
Step 5: Create Google App
Step 6: Create New Routes
Step 7: Create New GoogleloginController
Step 8: Create Blade File

 

Step 1: Make a project of Laravel 5.7 Or Laravel 5.8 Google Plus Login.

 

First of all we will install laravel 5.7 Or Laravel 5.8 application.The command to install laravel 5.7 or laravel 5.8 is given below.

composer create-project --prefer-dist laravel/laravel socialLogin

 

Step 2: Then Create users table and column.

 

Then after that, go to your database and create a table named users and column in it. You have been given the complete query of the users table below. You can select your database and go to sql and paste the query by creating the table.

CREATE TABLE `users` (
`id` int(100) NOT NULL,
`fname` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`google_id` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`remember_token` varchar(100) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` int(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

Step 3: Install Socialite Package For Google Plus

 

In this step we will learn to install socialite packege.

composer require laravel/socialite

 

Step 4: add service provider and alias.

 

After installing the Socialite Package, we will add the service of provider and alias to the config/app.php file.

'providers' => [
Laravel\Socialite\SocialiteServiceProvider::class,
],
'aliases' => [
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
],

 

Step 5: Create Google App

 

In the third step you will have to create a google app account. You can create this by visiting this link of the Goolgel app. After creating google account you will need cliend id and secret id.

https://console.developers.google.com/

You can create a client id and secret that you want to add to this config/services.php file. You can see below.

config/services.php

return [
....
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('GOOGLE_CALLBACK_URL'),
],
]

 

Step 6: Pass URL into Routes File

 

Route::get('googlelogin', function () {
return view('googlelogin');
});
Route::get('auth/google', 'GoogleloginController@redirectToGoogle');
Route::get('auth/google/callback', 'GoogleloginController@handleGoogleCallback');

Step 7: Create New GoogleloginController

 

we need to add new controller and method of google auth that method will handle google callback url and etc, first put bellow code on your GoogleloginController.php file.

app/Http/Controllers/GoogleloginController.php

<?php
// GoogleloginController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Socialite;

class GoogleloginController extends Controller
{
/**
* Create a redirect method to google api.
*
* @return void
*/
public function redirect()
{
return Socialite::driver('google')->redirect();
}
/**
* Return a callback method from google api.
*
* @return callback URL from google
*/
public function callback()
{
$userSocial = Socialite::driver('google')->user();
//return $userSocial;
$finduser = User::where('google_id', $userSocial->id)->first();
if($finduser){
Auth::login($finduser);
return Redirect::to('/');
}else{
$new_user = User::create([
'fname' => $userSocial->name,
'email' => $userSocial->email,
'google_id'=> $userSocial->id
]);
Auth::login($new_user);
return redirect()->back();
}
}
}

 

Step 8: Create Blade File

 

Ok, now at last we need to add blade view so first create new file googlelogin.blade.php file and put bellow code:

resources/views/googlelogin.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-12 row-block">
<a href="{{ url('auth/google') }}" class="btn btn-lg btn-primary btn-block">
<strong>Login With Google</strong>
</a> 
</div>
</div>
</div>
@endsection

Post navigation

How to Generate 6 Digit Unique Random Numbers in PHP?
How to Generate 4 Digit Random Number by Javascript with Example?

Recent Posts

  • Include() Function in PHP 8.3 April 30, 2025
  • Word, Paragraph, Sentence & Character Counter Tool Create Using JavaScript HTML & CSS April 30, 2025
  • ChatGPT Random Number Generator April 29, 2025
  • Random Number Generator in PHP 8.4 April 27, 2025
  • Top 5 Convertcase.net Alternatives Websites April 26, 2025
  • ChatGPT Language Translator April 22, 2025
  • Word Converter April 19, 2025
  • ChatGPT Word Converter April 19, 2025
  • Google Random Number Generator April 18, 2025
  • ChatGPT Find and Replace Text April 16, 2025
  • DeepSeek Word Counter April 16, 2025
  • Pythagorean Theorem Calculator Find a, b & c April 12, 2025
  • Desmos Scientific Calculator April 11, 2025
  • ChatGPT Text to PDF Converter April 11, 2025
  • Calligraphy Font Generator Online April 11, 2025
  • Angle Conflict Detector April 10, 2025
  • Integer Sequence Calculator April 9, 2025
  • Hypotenuse Calculator & Converter April 8, 2025
  • Find and Replace Word Calculator & Converter April 7, 2025
  • HTML Heading Tag Generator (H1 to H6) April 7, 2025
  • ChatGPT Text Font Generator April 5, 2025
  • Text Font Style Generator April 5, 2025
  • AI Text Calculator April 3, 2025
  • Chatgpt AI Text Humanizer April 3, 2025
  • Comma Remover Calculator April 3, 2025
  • Comma Separator Calculator April 3, 2025
  • Parentheses Removal Calculator April 3, 2025
  • Top 3 fastdl.app Competitors & Alternatives Websites April 1, 2025
  • Top 5 sssinstagram.com Alternatives & Competitors Website March 28, 2025
  • Eloquent Count Query Laravel 12 With Example March 26, 2025

Calculators & Converter Tools

MD5 Hash Generator

Hypotenuse Calculator

Find and Replace Word Calculator

HTML Heading Tag Generator

Text Font Style Generator

AI Text Converter

Comma Remover Calculator

Comma Separator Calculator

Parentheses Removal Calculator

Slope Calculator & Converter

Temprature Converter

Speed Converter

What is My IP

Your Internet Speedtest

Ratio Calculator

Alexa Rank Checker

GST Calculator

Square(√) Root Calculator

Prime Numbers Calculator

Area of Circle Calculator

Percentage(%) Calculator

Hexa to Decimal Converter

Binary to Decimal Converter

HTML Minify Tools

Remove Blank Lines Minify Tools

Word Counter

Multiplication Calculator

Add Fraction Calculator

ODD Number Calculator

Even Number Calculator

Learn Programming Blog, Tutorials, PHP, MySQL, JavaScript & JQuery, Ajax, WordPress, Laravel, Web Development, Many Tools and Demos with Experts PHP.powered by Experts PHP

About us|Terms and Condition|Privacy Policy|Sitemap
Kmspico Download | Official KMS Activator Website [New Version 2024] Vavada вход позволяет мгновенно попасть в мир азартных игр и бонусов! Получи доступ и начни выигрывать прямо сейчас. Получите доступ без ограничений через vavada регистрация и наслаждайтесь всеми функциями платформы! AMLBot crypto service online: amlbot check - ETH, USDT TRC20/ERC20 and 5000+ coins. Receiving funds of illegal origin could lead the risk of having your funds frozen. The USDT is being tested for scams, mixers, darknet market