1 <?php
2
3 namespace App\Http\Middleware;
4
5 use Closure;
6 use Illuminate\Contracts\Auth\Factory as Auth;
7
8 class Authenticate
9 {
10 /**
11 * The authentication guard factory instance.
12 *
13 * @var \Illuminate\Contracts\Auth\Factory
14 */
15 protected $auth;
16
17 /**
18 * Create a new middleware instance.
19 *
20 * @param \Illuminate\Contracts\Auth\Factory $auth
21 * @return void
22 */
23 public function __construct(Auth $auth)
24 {
25 $this->auth = $auth;
26 }
27
28 /**
29 * Handle an incoming request.
30 *
31 * @param \Illuminate\Http\Request $request
32 * @param \Closure $next
33 * @param string|null $guard
34 * @return mixed
35 */
36 public function handle($request, Closure $next, $guard = null)
37 {
38 if ($this->auth->guard($guard)->guest()) {
39 return response('Unauthorized.', 401);
40 }
41
42 return $next($request);
43 }
44 }
45