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.
Use the below given steps to create rest api using jwt auth in laravel 7/6/5:
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
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
In this step, run the below command and install jwt auth package :
composer require tymon/jwt-auth
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