In this tutorials we will learn about middleware in laravel framework . Directory of middleware and where we register middleware in laravel project . When you install your laravel project . Middleware directory create in your App\Http\ folder .
Into the Middleware folder you can create your customized middleware as per you requirement. Like below we are create a middleware for website redirect to http:// to https:// .
<?php namespace App\Http\Middleware; use Closure; use Illuminate\Support\Facades\App; class HttpsProtocol { public function handle($request, Closure $next){ if (!$request->secure() && App::environment() === 'production') { return redirect()->secure($request->getRequestUri()); } return $next($request); } } ?>
when you are create a middleware as per your requirement . Then you have to register your middleware in Kernal.php file . Kernal.php file find inside Http folder . and register as per you convenience .