ronaldkwandy

Authenticate

Aug 12th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  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.         $this->auth = $auth;
  25.     }
  26.  
  27.     /**
  28.      * Handle an incoming request.
  29.      *
  30.      * @param  \Illuminate\Http\Request  $request
  31.      * @param  \Closure  $next
  32.      * @param  string|null  $guard
  33.      * @return mixed
  34.      */
  35.     public function handle($request, Closure $next, $guard = null) {
  36.         if ($this->auth->guard($guard)->guest()) {
  37.             return response('Unauthorized.', 401);
  38.         }
  39.  
  40.         return $next($request);
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment