has('group_by')) { $sanitized['group_by'] = strtolower( preg_replace('/[^a-z_]/', '', trim($this->group_by)) ); } // Sanitize year: convert to integer, remove any non-numeric characters if ($this->has('year')) { $sanitized['year'] = (int) preg_replace('/[^0-9]/', '', $this->year); } $this->merge($sanitized); } /** * Get the validation rules that apply to the request. */ public function rules(): array { return [ 'group_by' => ['sometimes', 'string', 'alpha', Rule::in(['department', 'region'])], 'year' => 'sometimes|integer|min:2000|max:2100', ]; } }