1. Go to this page and download the library: Download bkstar123/social-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCustomerSocialAccountsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customer_social_accounts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('customer_id')->unsigned()->index();
$table->string('provider_name');
$table->string('provider_user_id');
$table->timestamps();
$table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade');
$table->unique(['provider_name', 'provider_user_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customer_social_accounts');
}
}
namespace App;
use App\Models\Customer;
use Bkstar123\SocialAuth\Models\Abstracts\SocialAccountBase;
class CustomerSocialAccount extends SocialAccountBase
{
public function getUserModelClass()
{
return Customer::class;
}
}
protected function getSocialAccountModelClass()
{
return CustomerSocialAccount::class; // Surely, you must autoload this class
}
protected function getUserModelClass()
{
return Customer::class; // Surely, you must autoload this class
}
protected function getSocialAccountModelClass()
{
return CustomerSocialAccount::class; // Surely, you must autoload this class
}
protected function beforeFirstSocialLogin($user, $socialUser)
{
if (!$user->email_verified_at) {
$user->email_verified_at = Carbon::now();
$user->save();
}
}
protected function postSocialLogIn()
{
return redirect()->route('dashboard');
}
protected function actionIfFailingToGetSocialData()
{
return redirect()->route('customer.login');
}
protected function guard()
{
return Auth::guard('customer');
}
config/auth.php
app/User.php
app/Http/Controllers/Auth/LoginController.php
routes/web.php
html
<!-- For Google login -->
<a href="{{ route('login.social', ['provider' => 'google']) }}"
class="btn btn-danger">
<i class="fa fa-google"></i> Google
</a>
app/Models/Customer.php
config/auth.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.