throttleKey(), function (Request $request) use ($case) { $route = $request->route(); throw_if($route === null, InvalidArgumentException::class, 'Expected an active route when applying a server resource limit.'); $server = $route->parameter('server'); throw_unless($server instanceof Server, InvalidArgumentException::class, 'Expected route parameter [server] to be a server.'); return $case->limit()->by($server->uuid); }); } } public function throttleKey(): string { return mb_strtolower("api.client:server-resource:{$this->name}"); } /** * Returns a middleware that will throttle the specific resource by server. This * throttle applies to any user making changes to that resource on the specific * server, it is NOT per-user. */ public function middleware(): string { return ThrottleRequests::using($this->throttleKey()); } public function limit(): Limit { return match ($this) { self::Backup => Limit::perMinutes(15, 3), self::Database => Limit::perMinute(2), self::FilePull => Limit::perMinutes(10, 5), self::Subuser => Limit::perMinutes(15, 10), self::Websocket => Limit::perMinute(5), default => Limit::perMinute(2), }; } }