1class UserController extends Controller
2{
3 /**
4 * Instantiate a new controller instance.
5 *
6 * @return void
7 */
8 public function __construct()
9 {
10 $this->middleware('auth');
11
12 $this->middleware('log')->only('index');
13
14 $this->middleware('subscribed')->except('store');
15 }
16}
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}
1<?php
2
3namespace App\Http\Middleware;
4
5use Closure;
6
7class BeforeMiddleware
8{
9 public function handle($request, Closure $next)
10 {
11 // Perform action
12
13 return $next($request);
14 }
15}
16
17
1<?php
2
3namespace App\Http\Middleware;
4
5use Closure;
6
7class CheckType
8{
9 public function handle($request, Closure $next)
10 {
11 // Perform action
12
13 return $next($request);
14 }
15}