Garry Taylor

Garry Taylor


JWT for Laravel


Make sure you include this package as part of your Laravel project. You can do so by running the composer command from below.

composer require babicaja/jwt-4laravel

Getting started

First register the service provider with the artisan vendor:publish command. This will ensure all the bindings are in place and it will copy the default configuration file to your app's config folder.

php artisan vendor:publish // Choose JWT4L\Providers\JWTServiceProvider from the list

Inspect the newly created config/jwt.php file. For now, you can leave it as it is (don't forget to change the secret key for production). Details about the configuration are covered in this section.

Now everything is in place and you can start using the JWT for Laravel's functionality. Easiest way to see it in actions is using the Token Facade provided by the package, and through artisan tinker. If you are able to see a similar output as the one below, you are all set.

php artisan tinker
Psy Shell v0.9.9 (PHP — cli) by Justin Hileman
>>> Token::create()
=> "eyJ0eXAiOiJKV1QiLCJhbGciOiJzaGEyNTYifQ==.eyJpYXQiOiIyMDE5LTA3LTAyVDE1OjAyOjQ5LjkzMTQwMloiLCJleHAiOiIyMDE5LTA3LTAyVDE1OjE3OjQ5LjkzMTQ2M1oifQ==.fa0f19c3a2a444d72bb58feb54227677e52c65e35f3db21b31673520ddb16c86"


Out of the box the configuration file comes with default values which you can use as they are. You should probably change the secret for any production code. You can set the values directly in the config/jwt.php file or preferably by setting the appropriate .env values.


return [
‘algorithm’ => env(‘JWT_ALG’, ‘sha256’), //hash_hmac_algos()
‘expires’ => env(‘JWT_EXP’, 15), // minutes
‘secret’ => env(‘JWT_KEY’, ‘secret’),
‘checks’ => [

  • Algorithm
  • This value can be any of the algorithms from PHP’s hash_hmac_algos(). The algorithm defined here is used for signing and comparing the JWT signature.
  • Expires
  • When creating a new Token, by default an exp claim is added to the Payload section. The amount of minutes defined here will set the expire date from the moment of creation.
  • Secret
  • This value is used in conjunction with the defined algorithm for signing and comparing the JWT signature.
  • Checks
  • You should add your custom checks here or choose which one of the defaults you want to use. It’s strongly recommended to use the default ones, but you are free to do as you wish.


There are a few ways to use the JWT for Laravel package:

  • Token Facade
  • Combines the functionality of the \JWT4L\Token\Generator, JWT4L\Token\Validator and \JWT4L\Token\Parser Token Managers. This allows the user to create, validate and parse the JWT through one interface anywhere in the application.
Example of Token Facade usage
$token = Token::create() // create a JWT
$payload = Token::payload($token) // retrieve the Payload section from the JWT
  • Token Managers
  • There are three Token Managers:
  • \JWT4L\Token\Generator is responsible for JWT creation
  • JWT4L\Token\Validator validates the provided JWT against the Checks
  • \JWT4L\Token\Parser does the parsing of JWT
  • All of the Token Managers are bound to Laravel’s Service Container which allows you to inject them into constructors or method calls.
Example of Token Manager usage

namespace App\Http\Controllers;

class TokenController extends Controller
public function generate(\JWT4L\Token\Generator $generator)
return response($generator->create());

  • JWTGuard
  • The package provides a custom Guard called JWTGuard. Laravel’s Auth will be automatically extended with this Guard but you need to manually configure it in the config/auth.php
    ‘guards’ => [
‘web’ => [
‘driver’ => ‘session’,
‘provider’ => ‘users’,

    'api' =&gt; [
        'driver' =&gt; 'token',
        'provider' =&gt; 'users',
        'hash' =&gt; false,

    'jwt' =&gt; [
        'driver' =&gt; 'jwt',
        'provider' =&gt; 'users',

  • Now you can assign this guard to any route using the auth:jwt middleware.
Example of a route protected by the JWTGuard
Route::middleware(‘auth:jwt’)->post(‘/user’, function (Request $request) {
return $request->user();
  • One important note regarding the JWTGuard implementation. The Guard will try to extract the user identifier from the sub (payload) claim of the provided token, so you should make sure that the logic responsible for token creation sets this claim as in the example bellow.
Example of setting a custom claim


The package provides three JWT checks out of the box:

  • \JWT4L\Checks\Structure verifies the expected header.payload.signature structure
  • \JWT4L\Checks\Signature validates the hashed signature
  • \JWT4L\Checks\Expired checks has the token expired

You can define your custom check by creating a class which implements the \JWT4L\Checks\CheckContract interface and include it in the config/jwt.phpfile.


namespace app\Checks;

use Carbon\Carbon;
use JWT4L\Checks\CheckContract;

class Friday implements CheckContract
* Do necessary checks and throw a specific exception if conditions are not met.
* @param string $token
* @return void
* @throws mixed
public function validate(string $token)
if (!Carbon::now()->isFriday()) throw new \Exception(“It’s not Friday”);


return [
‘algorithm’ => env(‘JWT_ALG’, ‘sha256’), //hash_hmac_algos()
‘expires’ => env(‘JWT_EXP’, 15), // minutes
‘secret’ => env(‘JWT_KEY’, ‘secret’),
‘checks’ => [

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow me on Facebook | Twitter

Learn More about

PHP with Laravel for beginners - Become a Master in Laravel

Projects in Laravel: Learn Laravel Building 10 Projects

Laravel for RESTful: Build Your RESTful API with Laravel

Fullstack Web Development With Laravel and Vue.js

Laravel 5.8 Ajax CRUD tutorial using Datatable JS

Laravel 5.8 Tutorial from Scratch for Beginners

Build RESTful API In Laravel 5.8 Example

Login with Google in Laravel 5.8 App using Socialite Package

Laravel PHP Framework Tutorial - Full Course for Beginners (2019)

#laravel #security #json #php #web-development

What is GEEK

Buddha Community

JWT for Laravel
Seamus  Quitzon

Seamus Quitzon


Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.


namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
    protected $fillable = [

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.


Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

sophia tondon

sophia tondon


Top Laravel Development Company India | Laravel Development Services

Laravel is a popular framework for website development, acquiring 25.85% of the PHP framework market share. As a most admired framework among PHP frameworks, it is being utilized for e-commerce, enterprise, social media, and various different types of websites.

There are more than 1 million websites worldwide available over the web that are created using Laravel. Laravel framework is the first preference of PHP developers as it allows them to develop highly scalable, flexible, and faster web applications.

Surely, you, too, would want to deliver a splendid and unhindered user experience to your target audience over the web. Laravel framework can help you achieve this pursuit at ease; all you need to do is hire Laravel developers from reliable & coveted hosts. But! There is no shortage of Laravel development companies that promise to deliver an excellent solution, but only some are able to deliver top-notch quality.

Therefore, I have decided to enlist top Laravel development companies to help you find a reliable and expert host for web development. So, stay hooked with me till the end of this article and explore the best Laravel developers in 2021.

While creating this list, I have kept the following pointers in reflection:

Years of excellence (average 8 years)
Rewards & Recognition
Client rating & feedback
Hourly/Monthly Price
Number of happy clients
Number of successfully launched projects
Minimum man-years experience
So, let’s not waste a minute and glance at top Laravel development companies to hire for creating excellent web solutions.

Read More -

#hire a laravel developer #hire laravel developer #hire laravel developers #laravel developer for hire #laravel developers #laravel developers for hire

sophia tondon

sophia tondon


Hire Laravel Developers | Laravel Development Company, Services India

Looking for a team of experienced offshore Laravel developers? Hire a top dedicated team of Laravel developers from India online with 6+ years of average experience on an hourly or dedicated (monthly) basis from ValueCoders and enjoy easy hiring, quality work, and on-demand scalability at up to 60% less cost.

Our offshore Laravel development experts are fully competent to build scalable, secure, and robust custom web apps suiting your business requirements.

First Time Right Process
Complete Control Over The Team
Certified Laravel Coders
Agile & DevOps Enablement
Non-Disclosure Agreement
No Contract Lock-Ins

Visit Us-

#hire a laravel developer #hire laravel developer #laravel development #hire laravel experts #find laravel developers #laravel development services india

Seamus  Quitzon

Seamus Quitzon


How to perform migration rollback in laravel

As we know that laravel migration provides very simple way to create database table structure. We need to create migration file and write table structure then migrate that migration. Sometimes we need to rollback that migration. So here we will discuss about the migration rollback in laravel.

We can run the rollback artisan command to rollback on a particular step. We can execute the following artisan command.

php artisan migrate:rollback --step=1

Every time when we will rollback, we will get the last batch of migration.

**Note: **This rollback command will work on laravel 5.3 or above version. For the version below 5.3, there is no command available for migration rollback in laravel.

We can also use the following command to rollback and re migrate.

php artisan migrate:refresh --step=2

It will rollback and remigrate last two migration.

You can also checkout the article for executing single migration by clicking on the link below.

How to migrate single migration in laravel

#laravel #how to perform rollback migration in laravel #laravel migration rollback #migration refresh in laravel #migration rollback batch in laravel #migration rollback for one specific migration #migration rollback in laravel

Seamus  Quitzon

Seamus Quitzon


How to Hire Laravel Developers and How Much Does It Cost.

There are many recruitment cycles to hire Laravel developers for developing your high-end applications. It is important to choose the right cycle that suits the requirements of the unique needs of your business and development. The following are some of the most commonly used recruitment methods to hire the best Laravel developers.

1. Laravel freelance developers

The Freelance Laravel developers are easily available on many different sites that can cater to your company’s requirements. If you already have a team of developers and only require a small amount of temporary work to be done. Hiring freelance Laravel developers is the best model for you.

2. Laravel Offshore Developers

When it comes to offshore Laravel developers, it is more similar to the freelance developer but with enhanced security and more trustworthy developers duly NDA signed with a legal contract.

3. Laravel in-house Developers

If you already have a team of Laravel developers and if your company needs a consistent requirement for Laravel development, it should probably hire the best in-house Laravel developer for your team which can be on a permanent or contract basis.

4. Outsource Laravel developer/team

Outsourcing is also similar to offshore development. Based on the requirement and the size of your in-house team, you can hire an offshore Laravel developer or a team.

5. Laravel Development company

If you or your company has no idea over the technical knowledge of your project development, it is the best choice to involve the technical team of experts to do the work. In that case, hiring a Laravel development company can help you with all the requirements and many added benefits comes along for a longer-term. If you are interested in ROI, hiring the best Laravel development company is everything that your business deserves.

Hourly Rate of Laravel Developer

The Laravel developer salary may differ depending on the experience of the developer, the hiring company size, the country, and many other factors. When we are talking about the national average salary of a Laravel developer, it is the approximate number taken from a number of Laravel developers across the country.

According to Payscale, the average Laravel developer salary is $64,479/ year in the United States. The highly experienced professional developer earns about $94k and freshers earn about $43k.

This means that the hourly rate of Laravel developer is about $24.09 / hour in the US. Here is the list of the national salary of Laravel developer salaries across countries. All the information below is with reference to the information given in

Laravel developer Salary in India – Rs. 546,000

Laravel developer salary in Canada – $110,000

Laravel developer Salary in Germany – €46,454

Laravel developer Salary in UK – £68,000

All the details mentioned in the above table are taken from Payscale on the 27th of May, 2020.

So, it is a wise option to consider hiring the best offshore developers for your project if you are cost-effective solutions.

We, Agira technologies are a technology solution company with business services and domain solutions that support global clients who comprise the current world economy. Some of the exclusive services that we offer are web development, mobile app development, Blockchain, IoT, and DevOps Consulting.

#laravel #hire laravel developer #hire laravel developer company #hire laravel developer india #laravel developer cost #laravel developer skills