*/ public function rules(): array { return [ 'documentation_category_id' => ['nullable', 'integer', 'exists:documentation_categories,id'], 'title' => ['required', 'string', 'max:220'], 'slug' => ['nullable', 'string', 'max:240', Rule::unique('documentation_documents', 'slug')], 'summary' => ['nullable', 'string', 'max:500'], 'body' => ['nullable', 'string'], 'status' => ['required', Rule::in([DocumentationDocument::STATUS_DRAFT, DocumentationDocument::STATUS_PUBLISHED, DocumentationDocument::STATUS_ARCHIVED])], 'is_featured' => ['nullable', 'boolean'], 'version' => ['required', 'string', 'max:50'], 'reference' => ['nullable', 'string', 'max:100'], 'attachment' => ['nullable', 'file', $this->uploadSizeRule(), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))], 'attachments' => ['nullable', 'array'], 'attachments.*' => ['file', $this->uploadSizeRule(), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))], ]; } /** * Enforce the upload ceiling in bytes instead of relying on Laravel's * file `max` rule, keeping the security boundary explicit. * * @return \Closure(string, mixed, \Closure(string): void): void */ private function uploadSizeRule(): \Closure { return static function (string $attribute, mixed $value, \Closure $fail): void { if (! $value instanceof UploadedFile || ! $value->isValid()) { return; } $size = $value->getSize(); if ($size === false || $size > self::MAX_UPLOAD_BYTES) { $fail(sprintf('The %s must not be larger than 1 MB.', $attribute)); } }; } }