1//Controller add
2
3public function __construct()
4 {
5 $this->middleware([
6 'auth',
7//About 20 requests per minute to Cotroller and error if there are too many requests
8 'throttle:20,1'
9 ]);
10 }
1//In Laravel we use throttle middleware to restrict the amount of traffic
2//for a given route or group of routes. The throttle middleware accepts two parameters
3//that determine the maximum number of requests that can be made in a given number of minutes.
4//For example:
5//Here 60 is number of requests you can make in 1 minute.
6
7Route::middleware('throttle:60,1')->get('/user', function () {
8 //
9});
10
1<?php
2
3namespace App\Http\Middleware;
4
5use Closure;
6
7class CheckAge
8{
9 /**
10 * Handle an incoming request.
11 *
12 * @param \Illuminate\Http\Request $request
13 * @param \Closure $next
14 * @return mixed
15 */
16 public function handle($request, Closure $next)
17 {
18 if ($request->age <= 200) {
19 return redirect('home');
20 }
21
22 return $next($request);
23 }
24}