How to Install JWT Auth in Laravel Project
Hello Programmers, welcome to our technical blogs, today we will see How to install JWT Auth in Laravel, I want to tell you that Before installation JWT Auth, you need to know some tools and programming languages, which will be easy for you to install.
What you need to know before JWT installation
- PHP Programming
- Laravel Framework
- Know how to use postman
Let me tell you that there are 2 ways to install JWT.
- You can install it by running the command given below directly from the command prompt.
composer require tymon/jwt-auth
2. Run the composer update command by placing the following code in the composer.json file
After putting the above line in composer.json we need to run this command ‘update composer‘
We can install JWT Auth in our project by any of the above-given steps.
You need to find out which version of your Laravel project is working, if your version of the Laravel project is 5.4 or less then you need to add providers, Go to your Laravel project directory and find the app.php file, which will be in config/app.php
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
After running the above command, if your JWT Auth installation process is correct, then the jwt.php file will be created in the directory of your project, which will be in the path of config/jwt.php
If the jwt.php file is created then everything is fine, now we are going to generate a JWT secret
php artisan jwt:secret
Congratulations, I hope you have got JWT_SECRET after running this command.
This command will also update your .env file, if your .env file is still not updated with JWT secret then there is no problem, according to the image given below you can update your secret in your .env file.
But one thing should be kept in mind that you have to use your secret which you would have got from your command prompt.
Need more detailed instructions? Check out the Laravel Installation Docs
I believe this post has been helpful, I hope you have successfully installed JWT Auth – Laravel.
Read more about our other posts.