Raviya Technical
Published in

Raviya Technical

Laravel Basic | Laravel Middleware Tutorial With Example

php artisan make:middleware CheckType
<?phpnamespace App\Http\Middleware;use Closure;class CheckType{/*** Handle an incoming request.** @param  \Illuminate\Http\Request  $request* @param  \Closure  $next* @return mixed*/public function handle($request, Closure $next){if ($request->type != 2) {return response()->json('Please enter valid type');}return $next($request);}}
<?phpnamespace App\Http;use Illuminate\Foundation\Http\Kernel as HttpKernel;class Kernel extends HttpKernel{..../*** The application's route middleware.** These middleware may be assigned to groups or used individually.** @var array*/protected $routeMiddleware = [....'checkType' => \App\Http\Middleware\CheckType::class,];}
<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;class HomeController extends Controller{public function checkMD(){dd('checkMD');}}



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store