middlware in laravel code example

Example 1: laravel make middleware

php artisan make:middleware CheckAge

Example 2: middleware command in laravel

php artisan make:middleware NameOfTheMiddleware

Example 3: middleware in laravel

<?php

namespace App\Http\Middleware;

use Closure;

class BeforeMiddleware
{
    public function handle($request, Closure $next)
    {
        // Perform action

        return $next($request);
    }
}

Example 4: middleware in laravel

<?php

namespace App\Http\Middleware;

use Closure;

class CheckType
{
    public function handle($request, Closure $next)
    {
        // Perform action

        return $next($request);
    }
}

Tags:

Php Example