flarum/framework · error · InvalidParameterException

A model must be specified

Error message

A model must be specified

What it means

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.

Solutions

  1. Pass a valid 'model' query parameter matching one of the keys in $this->entities (e.g. users, discussions).
  2. Before calling the endpoint, inspect the available models and pick one dynamically.
  3. Add client-side validation that a model is selected before issuing the statistics request.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at extensions/statistics/src/Api/Controller/ShowStatisticsData.php:79 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/b6f4d5573895b9d3. Report an issue: GitHub.

Appendix: source

Thrown at extensions/statistics/src/Api/Controller/ShowStatisticsData.php:79

        $actor->assertAdmin();

        $query = $request->getQueryParams();

        $reportingPeriod = Arr::get($query, 'period');
        $model = Arr::get($query, 'model');
        $customDateRange = Arr::get($query, 'dateRange');

        return new JsonResponse($this->getResponse($model, $reportingPeriod, $customDateRange));
    }

    private function getResponse(?string $model, ?string $period, ?array $customDateRange): array
    {
        if ($period === 'lifetime') {
            return $this->getLifetimeStatistics();
        }

        if (! Arr::exists($this->entities, $model)) {
            throw new InvalidParameterException('A model must be specified');
        }

        if ($period === 'custom') {
            $start = (int) $customDateRange['start'];
            $end = (int) $customDateRange['end'];

            if (! $customDateRange || ! $start || ! $end) {
                throw new InvalidParameterException('A custom date range must be specified');
            }

            // Seconds-based timestamps
            $startRange = Carbon::createFromTimestampUTC($start)->toDateTime();
            $endRange = Carbon::createFromTimestampUTC($end)->toDateTime();

            // We can't really cache this
            return $this->getTimedCounts($this->entities[$model][0], $this->entities[$model][1], $startRange, $endRange);
        }

View on GitHub (pinned to 4b939f6853)