lsky-pro/app/Http/Middleware/CheckIsEnableApi.php
2022-03-16 10:00:58 +08:00

27 lines
520 B
PHP

<?php
namespace App\Http\Middleware;
use App\Enums\ConfigKey;
use App\Http\Result;
use App\Utils;
use Closure;
use Illuminate\Http\Request;
class CheckIsEnableApi
{
use Result;
public function handle(Request $request, Closure $next)
{
if (! Utils::config(ConfigKey::IsEnableApi)) {
if ($request->expectsJson()) {
return $this->fail('管理员未启用 API')->setStatusCode(403);
}
abort(404);
}
return $next($request);
}
}