2FAuth/app/Http/Middleware/AdminOnly.php

27 lines
514 B
PHP
Raw Normal View History

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