In this tutorial, we are going to learn how to implement Facebook login using Socialite package in Laravel. When your users need to log to your application using their Facebook, this will be the easiest way to do it.
Prerequisites
Laravel
To Continue with this tutorial, you should have installed Laravel 8 in your pc. If you are still not installed Laravel in your machine you can configure it from here.
Setting up the Project
First you need to create a new laravel project by running below command in your terminal
use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Jetstream\HasProfilePhoto; use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable { use HasApiTokens; use HasFactory; use HasProfilePhoto; use Notifiable; use TwoFactorAuthenticatable;
/** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', 'fb_id', ];
/** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'two_factor_recovery_codes', 'two_factor_secret', ];
/** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ];
/** * The accessors to append to the model's array form. * * @var array */ protected $appends = [ 'profile_photo_url', ]; }
Install Socialite Package
Now we meed to install Socialite package in to our application.
1
composer require laravel/socialite
Then you need to register Socialite package in our config/app.php file’s provider array and alias array:
use Illuminate\Support\Facades\Route; use App\Http\Controllers\SocialController;
/* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */
To run your application run below command in your termial:
1
php artisan serve
Then navigate to following URL:
1
http://127.0.0.1:8000/login
Conclusion
In this tutorial, we implemented password change functionality in Laravel. If you have any issue regarding this tutorial, mention your issue in comment section or reach me through my E-mail..