Importing Package Docs
Add documentation to your packages
Importing Package Docs
OI Laravel Documentation supports importing documentation from packages. If you're building a Laravel package, you can include documentation that users will automatically import with php artisan doc:import.
Creating Package Documentation
To add documentation to your Laravel package:
Step 1: Create docs Directory
In your package root, create the documentation directory:
mkdir -p docsStep 2: Create Package meta.json
Create docs/meta.json with package metadata:
{
"type": "package",
"name": "vendor/package-name",
"title": "Package Documentation Title",
"description": "Description of your package",
"version": "1.0.0",
"order": 50
}Required Fields
| Field | Type | Required | Purpose |
|---|---|---|---|
type | string | Yes | Must be "package" |
name | string | Yes | Package identifier (vendor/name) |
title | string | Yes | Display name |
description | string | Yes | Brief description |
version | string | No | Package version |
order | number | No | Sort order in docs menu |
Step 3: Create Section Structure
Create sections within your documentation:
docs/
āāā meta.json
āāā _index.md # Package homepage
āāā getting-started/
ā āāā meta.json
ā āāā _index.md
ā āāā installation.md
āāā configuration/
ā āāā meta.json
ā āāā _index.md
ā āāā settings.md
āāā guides/
āāā meta.json
āāā _index.md
āāā common-tasks.md
Step 4: Create Section meta.json Files
Each section needs meta.json:
{
"type": "section",
"title": "Getting Started",
"description": "Installation and setup",
"order": 1
}Step 5: Write Documentation Pages
Create markdown files with frontmatter:
---
title: Installation
description: How to install the package
order: 1
---
# Installation
Install via Composer:
```bash
composer require vendor/package-nameInstallation Steps
- Install the package
- Run setup command
- Configure settings
## Complete Package Example
Example package documentation structure:
vendor/api-client/ āāā composer.json āāā src/ ā āāā ApiClient.php āāā docs/ ā āāā meta.json ā āāā _index.md ā āāā getting-started/ ā ā āāā meta.json ā ā āāā _index.md ā ā āāā installation.md ā āāā api-reference/ ā ā āāā meta.json ā ā āāā _index.md ā ā āāā authentication.md ā ā āāā endpoints.md ā āāā guides/ ā āāā meta.json ā āāā _index.md ā āāā advanced-usage.md āāā ...
### Package meta.json
```json
{
"type": "package",
"name": "vendor/api-client",
"title": "API Client",
"description": "Comprehensive PHP client for REST APIs",
"version": "2.0.0",
"order": 50
}
Section meta.json
{
"type": "section",
"title": "Getting Started",
"description": "Installation and basic usage",
"order": 1
}Page Example
---
title: Installation
description: Install the API Client package
order: 1
---
# Installation
Install the package using Composer:
```bash
composer require vendor/api-clientConfigure API Key
Set your API key in .env:
API_CLIENT_KEY=your_api_key_here
Next Steps
See Authentication for API key setup.
## Slug Generation
When users import your package, the documentation slug is derived from the package name:
| Package Name | Documentation Slug |
|--------------|-------------------|
| `vendor/api-client` | `api-client` |
| `vendor/auth-guard` | `auth-guard` |
| `laravel/horizon` | `horizon` |
Users access imported documentation at:
/documentation/{slug}/
Example: Package `vendor/api-client` is accessible at `/documentation/api-client/`
## Version-Specific Documentation
Handle different versions of your package:
```markdown
---
title: Configuration
description: Configure the package
version: ">=2.0"
order: 2
---
# Configuration (v2.0+)
This documentation applies to version 2.0 and above.
## Breaking Changes
If upgrading from v1.x, see [Upgrade Guide](../migration.md).
Organizing Documentation
By Feature
docs/
āāā database/
āāā caching/
āāā authentication/
āāā queues/
By Audience
docs/
āāā user-guide/
āāā developer-guide/
āāā api-reference/
āāā admin-panel/
By Topic Type
docs/
āāā getting-started/
āāā tutorials/
āāā reference/
āāā how-to/
āāā troubleshooting/
Best Practices
- Clear structure - Organize logically for your users
- Minimal nesting - Keep 2-3 levels maximum
- Complete documentation - Include all features
- Examples - Provide code examples
- Table of contents - Help users navigate
- API reference - Document public APIs
- Update regularly - Keep docs in sync with code
Documentation Standards
File Naming
Use lowercase with hyphens:
ā getting-started.md
ā api-reference.md
ā GettingStarted.md
ā API_Reference.md
Frontmatter Fields
Always include:
---
title: Page Title
description: Brief description
order: 1
---Markdown Formatting
Use consistent heading structure:
# Page Title (h1)
## Section 1 (h2)
### Subsection 1.1 (h3)
Some content here.Including Code Examples
Show configuration and usage:
## Installation
```bash
composer require vendor/packageBasic Usage
use Vendor\Package\Client;
$client = new Client();
$response = $client->get('/endpoint');Configuration
Set in config/package.php:
return [
'key' => env('PACKAGE_KEY'),
'debug' => env('APP_DEBUG'),
];
## Linking Between Sections
Use relative links:
```markdown
[Installation Guide](/documentation/oi-laravel-documentation/getting-started/installation)
[API Reference](../api-reference/_index.md)
[Troubleshooting](../help/troubleshooting.md)
Adding Images
Include images in your documentation:
# Create images directory
mkdir docs/images
# Add your images
# docs/images/setup-flow.png
# docs/images/api-diagram.pngReference in markdown:

Testing Documentation
Verify your documentation structure:
# Check meta.json is valid JSON
jq empty docs/meta.json
# Check all sections have meta.json
find docs -type d -exec test -f {}'/meta.json' \; -o -print
# Check all markdown files have frontmatter
find docs -name '*.md' -exec grep -l '^---' {} \;Documentation Updates
When releasing new versions:
-
Update version in
docs/meta.json:json"version": "2.1.0" -
Add version notes to relevant pages:
markdown> **Added in v2.1**: This feature was introduced in version 2.1 -
Update examples to reflect current API
-
Create migration guides for breaking changes
Integration with Release Process
Add documentation generation to your release workflow:
#!/bin/bash
# Release script
# Update version in docs
sed -i "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" docs/meta.json
# Commit changes
git add docs/meta.json
git commit -m "docs: update version to $VERSION"
# Tag release
git tag v$VERSION
git push origin v$VERSIONDiscoverability
Improve documentation discovery:
- Write comprehensive README - Link to docs
- Add docs link to composer.json:
json
{ "docs": "https://your-site.com/documentation/your-package" } - Include documentation badge in README:
markdown
[](...)
Accessibility
Ensure documentation is accessible:
- Use semantic HTML - Proper heading hierarchy
- Alt text for images - Describe all images
- Color contrast - Sufficient contrast ratios
- Keyboard navigation - Support keyboard users
- Descriptive links - No "click here" links
Performance
Optimize documentation performance:
- Optimize images - Compress before including
- Limit code examples - Keep examples focused
- Structure clearly - Good navigation reduces load
Publishing Package
When publishing to Packagist:
- Create
docs/meta.jsonwith proper structure - Ensure all sections have required metadata
- Test with
doc:importcommand - Document in your README
Packagist users can then import with:
composer require vendor/package-name
php artisan doc:importValidation Checklist
Before publishing:
-
docs/meta.jsonis valid JSON -
typeis set to"package" - All sections have
meta.json - All pages have frontmatter with title
- All links are relative paths
- All images are included in docs/
- Documentation is up-to-date with code
- Examples compile and run
- Grammar and spelling checked
- Headings are hierarchical (h1 only in frontmatter)
Next Steps
- Import your package - See how users import docs
- Write Markdown - Learn markdown syntax
- View Generator Commands - Understand generation