{"record":{"id":"b6f4d5573895b9d3","repo":"flarum/framework","slug":"a-model-must-be-specified","errorCode":null,"errorMessage":"A model must be specified","messagePattern":"A model must be specified","errorType":"exception","errorClass":"InvalidParameterException","httpStatus":null,"severity":"error","filePath":"extensions/statistics/src/Api/Controller/ShowStatisticsData.php","lineNumber":79,"sourceCode":"        $actor->assertAdmin();\n\n        $query = $request->getQueryParams();\n\n        $reportingPeriod = Arr::get($query, 'period');\n        $model = Arr::get($query, 'model');\n        $customDateRange = Arr::get($query, 'dateRange');\n\n        return new JsonResponse($this->getResponse($model, $reportingPeriod, $customDateRange));\n    }\n\n    private function getResponse(?string $model, ?string $period, ?array $customDateRange): array\n    {\n        if ($period === 'lifetime') {\n            return $this->getLifetimeStatistics();\n        }\n\n        if (! Arr::exists($this->entities, $model)) {\n            throw new InvalidParameterException('A model must be specified');\n        }\n\n        if ($period === 'custom') {\n            $start = (int) $customDateRange['start'];\n            $end = (int) $customDateRange['end'];\n\n            if (! $customDateRange || ! $start || ! $end) {\n                throw new InvalidParameterException('A custom date range must be specified');\n            }\n\n            // Seconds-based timestamps\n            $startRange = Carbon::createFromTimestampUTC($start)->toDateTime();\n            $endRange = Carbon::createFromTimestampUTC($end)->toDateTime();\n\n            // We can't really cache this\n            return $this->getTimedCounts($this->entities[$model][0], $this->entities[$model][1], $startRange, $endRange);\n        }\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/extensions/statistics/src/Api/Controller/ShowStatisticsData.php#L61-L97","documentation":"Input validation guard in the statistics API controller. getResponse checks Arr::exists($this->entities, $model); it fires when the 'model' query parameter is missing or not one of the registered entity keys, meaning the admin statistics request did not name a statistics model this endpoint can report on.","triggerScenarios":"Thrown at extensions/statistics/src/Api/Controller/ShowStatisticsData.php:79 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a valid 'model' query parameter matching one of the keys in $this->entities (e.g. users, discussions).","Before calling the endpoint, inspect the available models and pick one dynamically.","Add client-side validation that a model is selected before issuing the statistics request."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}