tethys/app/Http/Middleware/Authenticate.php

48 lines
889 B
PHP
Raw Normal View History

2018-08-06 12:30:51 +00:00
<?php
namespace App\Http\Middleware;
2015-07-19 06:49:24 +00:00
use Closure;
use Illuminate\Contracts\Auth\Guard;
2018-08-06 12:30:51 +00:00
class Authenticate
{
2015-07-19 06:49:24 +00:00
2018-08-06 12:30:51 +00:00
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
2015-07-19 06:49:24 +00:00
2018-08-06 12:30:51 +00:00
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
2015-07-19 06:49:24 +00:00
2018-08-06 12:30:51 +00:00
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
2015-07-19 06:49:24 +00:00
2018-08-06 12:30:51 +00:00
return $next($request);
}
2015-07-19 06:49:24 +00:00
}