Laravel Sanctum SPA API Authentication

In this article, I will share with you how to integrate the Sanctum API Integration

#1: Install Laravel Project

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

#2: Setup Database

After successfully install laravel Application, Go to your project .env file and set up database credential and move next step :

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=here your database name 
DB_USERNAME=here database username
DB_PASSWORD=here database password 

#3 : Install Required Packages

We have required following packages for integrate sanctum api in our laravel application.

composer require laravel/sanctum

then after run following command in your terminal

php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

#4: Create Migration

 we require to get default migration for create new sanctum tables in our database. run the below's command

php artisan migrate

app/Http/Kernel.php 

'api' => [
    \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
    'throttle:api',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
],
Tags: