1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php namespace App\Http\Middleware;
- use Closure;
- use Illuminate\Contracts\Auth\Authenticator;
- use Illuminate\Contracts\Routing\Middleware;
- use Illuminate\Contracts\Routing\ResponseFactory;
- class AuthMiddleware implements Middleware {
-
- protected $auth;
-
- protected $response;
-
- public function __construct(Authenticator $auth,
- ResponseFactory $response)
- {
- $this->auth = $auth;
- $this->response = $response;
- }
-
- public function handle($request, Closure $next)
- {
- if ($this->auth->guest())
- {
- if ($request->ajax())
- {
- return $this->response->make('Unauthorized', 401);
- }
- else
- {
- return $this->response->redirectGuest('auth/login');
- }
- }
- return $next($request);
- }
- }
|