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

26 lines
483 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
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! Auth::user()->is_admin) {
throw new AuthorizationException;
}
return $next($request);
}
}