jwt auth in laravel. Here, we will show you how to create rest api using tymon/jwt-auth laravel 7/6/5.

This tutorial will guide you step by step on how to install jwt in laravel and create rest api using tymon/jwt-auth laravel 7/6/5.

Laravel 7/6/5 jwt Authentication Tutorial

Use the below given steps to create rest api using jwt auth in laravel 7/6/5:

  • Step 1: Install Laravel 7/6/5 App
  • Step 2: Configure Database
  • Step 3: Install jwt laravel
  • Step 4: Configure jwt in laravel
  • Step 5: Generate jwt secret key
  • Step 6: Add jwt Class in Model
  • Step 7: Add Api Routes
  • Step 8: Create Api Controller
  • Step 9: Run Development Server

Step 1: Install Laravel 7/6/5 App

First of all, run the following command on your command prompt to install laravel fresh setup for building** laravel 7/6/5 jwt auth Apis **app:

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

Step 2: Configure Database

Then, Navigate root directory of your installed laravel restful authentication api with passport tutorial project. And open** .env** file. Then add the database details as follow:

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

Step 3: Install jwt laravel

In this step, run the below command and install jwt auth package :

composer require tymon/jwt-auth

Step 4: Configure jwt in laravel

After successfully install jwt auth laravel. So, Open config/app.php and add jwt providers and aliases:

'providers' => [
….
'Tymon\JWTAuth\Providers\JWTAuthServiceProvider',
],
'aliases' => [
….
'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth',
'JWTFactory' => 'Tymon\JWTAuth\Facades\JWTFactory',
],

After that, run the below given command to publish the configuration file in Laravel for jwt auth:

1

php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"

#laravel

Laravel 7 jwt Authentication Rest API Tutorial
50.35 GEEK