2FAuth/app/Http/Middleware/AdminOnly.php
2023-03-26 17:13:32 +02:00

26 lines
483 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Facades\Auth;
class AdminOnly
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! Auth::user()->is_admin) {
throw new AuthorizationException;
}
return $next($request);
}
}