2015-07-08 03:34:58 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
2016-01-03 23:55:13 -05:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
|
|
|
class Authenticate
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
2016-01-03 23:55:13 -05:00
|
|
|
* @param string|null $guard
|
2015-07-08 03:34:58 -04:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-01-03 23:55:13 -05:00
|
|
|
public function handle($request, Closure $next, $guard = null)
|
2015-07-08 03:34:58 -04:00
|
|
|
{
|
2016-01-03 23:55:13 -05:00
|
|
|
if (Auth::guard($guard)->guest()) {
|
2015-07-08 03:34:58 -04:00
|
|
|
if ($request->ajax()) {
|
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
} else {
|
|
|
|
return redirect()->guest('auth/login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|