pai-sklep/app/Http/Middleware/AdminAuth.php

28 lines
646 B
PHP
Raw Normal View History

2021-11-20 22:12:35 +01:00
<?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");
}
}