pai-sklep/app/Http/Middleware/AdminAuth.php
2021-11-29 15:46:29 +01:00

27 lines
647 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");
}
}