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

28 lines
647 B
PHP
Raw Permalink 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();
2021-11-24 11:34:46 +01:00
if ($user && $user->isAdmin()) {
2021-11-20 22:12:35 +01:00
return $next($request);
}
throw new AccessDeniedHttpException("You must be an admin to access this path");
}
}