laravel middleware in constructor code example
Example 1: laravel make middleware
php artisan make:middleware CheckAge
Example 2: laravel middleware
<?php
namespace App\Http\Middleware;
use Closure;
class CheckAge
{
public function handle($request, Closure $next)
{
if ($request->age <= 200) {
return redirect('home');
}
return $next($request);
}
}
Example 3: create middleware laravel
php artisan make:middleware <middleware-name>
Example 4: middleware in laravel
<?php
namespace App\Http\Middleware;
use Closure;
class CheckType
{
public function handle($request, Closure $next)
{
return $next($request);
}
}