I have just started learning lumen micro framework and having trouble as my middleware doesn't seem to work. here's my code.
//defined middleware in route
$app->get('/hello/{name}', ['middleware' => 'shield','uses' => 'Sampcontroller@show']);
//registered middleware in app.php
$app->routeMiddleware([
'shield' => App\Http\Middleware\Agemiddleware::class,
]);
Here it is middleware code
public function handle($request, Closure $next){
if ($request->input('name') == "18") {
echo "hate yew";
}
return $next($request);
}
}
Fix you class name (just for convention). AgeMiddleware (rename the file and the class).
Go to the bootstrap/app.php and register your route middleware
Make sure you put this snippet above the return statement.
Hit /hello/18.
If this doesn't work, you probably have another route above this one getting /home/something get requests.