27 lines
646 B
PHP
27 lines
646 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|
|
|
class AdminAuth
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
$user = Auth::user();
|
|
if($user && $user->isAdmin()) {
|
|
return $next($request);
|
|
}
|
|
throw new AccessDeniedHttpException("You must be an admin to access this path");
|
|
}
|
|
}
|