hypothetical/app/Http/Middleware/Authenticate.php

31 lines
652 B
PHP
Raw Normal View History

<?php
namespace App\Http\Middleware;
use Closure;
2016-01-03 23:55:13 -05:00
use Illuminate\Support\Facades\Auth;
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
* @return mixed
*/
2016-01-03 23:55:13 -05:00
public function handle($request, Closure $next, $guard = null)
{
2016-01-03 23:55:13 -05:00
if (Auth::guard($guard)->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('/login');
}
}
return $next($request);
}
}