mohamed-ayman/laravel-postman-generator
Composer 安装命令:
composer require mohamed-ayman/laravel-postman-generator
包简介
Professional Laravel package to automatically generate Postman collections from your Laravel routes, controllers, validation rules, and middleware
README 文档
README
A professional Laravel package that automatically generates Postman collections from your Laravel routes, controllers, validation rules, and middleware. This package scans your entire Laravel project and creates a complete Postman collection with all the necessary information.
Features
✨ Comprehensive Route Scanning
- Automatically scans all Laravel routes
- Supports web, API, and custom route groups
- Configurable route inclusion/exclusion
🔍 Deep Controller Analysis
- Extracts controller methods and parameters
- Identifies Form Request classes
- Analyzes method signatures and dependencies
✅ Validation Rule Extraction
- Extracts validation rules from Form Requests
- Finds custom validation in controllers
- Generates example request bodies based on validation rules
🛡️ Middleware Analysis
- Detects authentication middleware (Sanctum, Passport, etc.)
- Extracts required headers from middleware
- Identifies CSRF protection and other security middleware
📦 Postman Collection Generation
- Generates complete Postman Collection v2.1.0 JSON
- Organizes routes into folders by path structure
- Includes variables for base URL and authentication tokens
- Adds default headers and authentication configuration
🌐 Postman API Integration
- Update existing Postman collections via API
- Create new collections programmatically
- Sync your Laravel API documentation automatically
Installation
From Packagist (After Publishing)
Once the package is published on Packagist, you can install it via Composer:
composer require mohamed-ayman/laravel-postman-generator
From GitHub (Before Publishing)
If the package is not yet on Packagist, add the GitHub repository to your composer.json:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dev-mohamed-ayman/laravel-postman-generator"
}
],
"require": {
"mohamed-ayman/laravel-postman-generator": "^1.0"
}
}
Then run:
composer require mohamed-ayman/laravel-postman-generator
Troubleshooting
If you encounter security advisories or installation issues, see INSTALLATION_TROUBLESHOOTING.md for solutions.
The package will automatically register its service provider.
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=postman-generator-config
This will create a config/postman-generator.php file where you can configure:
- Base URL for your API
- Collection name and description
- Output path for the generated JSON file
- Routes to include/exclude
- Postman API credentials (for API updates)
Usage
Basic Usage
Generate a Postman collection from your Laravel routes:
php artisan postman:generate
This will create a Postman collection JSON file at the configured output path (default: storage/app/postman-collection.json).
Advanced Usage
Custom Output Path
php artisan postman:generate --output=storage/app/my-api-collection.json
Custom Collection Name
php artisan postman:generate --name="My Awesome API"
Custom Base URL
php artisan postman:generate --base-url=https://api.example.com
Include Specific Routes
php artisan postman:generate --include=api --include=web
Or include all routes:
php artisan postman:generate --include=all
Exclude Routes
php artisan postman:generate --exclude=telescope --exclude=horizon
Update Postman Collection via API
First, configure your Postman API key and collection ID in the config file or environment:
POSTMAN_API_KEY=your-api-key-here POSTMAN_COLLECTION_ID=your-collection-id-here POSTMAN_WORKSPACE_ID=your-workspace-id-here
Then run:
php artisan postman:generate --update-api --collection-id=your-collection-id
Programmatic Usage
You can also use the package programmatically:
use MohamedAyman\LaravelPostmanGenerator\PostmanGenerator; $generator = app(PostmanGenerator::class); // Generate collection $collection = $generator->generate([ 'collection_name' => 'My API', 'base_url' => 'https://api.example.com', 'include_routes' => ['api'], ]); // Save to file $generator->saveToFile($collection, storage_path('app/my-collection.json')); // Update via API $generator->updateViaApi($collection, [ 'collection_id' => 'your-collection-id', ]);
How It Works
Route Scanning
The package scans all registered Laravel routes and extracts:
- URI patterns
- HTTP methods
- Route names
- Controller classes and methods
- Middleware stack
- Route parameters
Controller Analysis
For each controller method, the package:
- Uses reflection to analyze method signatures
- Identifies Form Request classes
- Extracts method parameters and types
- Reads docblocks for additional information
Validation Extraction
The package extracts validation rules from:
- Form Request Classes: Reads the
rules()method - Controller Methods: Parses
$request->validate()calls - Validator Facade: Finds
Validator::make()calls
Middleware Analysis
The package analyzes middleware to:
- Detect authentication requirements
- Extract required headers (Authorization, CSRF tokens, etc.)
- Identify custom middleware data requirements
Collection Generation
The generated Postman collection includes:
- All routes organized by path structure
- Request methods and URLs
- Request bodies with example data based on validation rules
- Required headers from middleware
- Route parameters as variables
- Authentication configuration
- Environment variables for base URL and tokens
Example Generated Collection Structure
{
"info": {
"name": "Laravel API Collection",
"description": "Auto-generated Postman collection from Laravel routes"
},
"item": [
{
"name": "Users",
"item": [
{
"name": "Get Users",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{base_url}}/api/users",
"host": ["{{base_url}}"],
"path": ["api", "users"]
}
}
},
{
"name": "Create User",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{token}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"string\",\n \"email\": \"example@email.com\",\n \"password\": \"string\"\n}"
},
"url": {
"raw": "{{base_url}}/api/users",
"host": ["{{base_url}}"],
"path": ["api", "users"]
}
}
}
]
}
],
"variable": [
{
"key": "base_url",
"value": "http://localhost",
"type": "string"
},
{
"key": "token",
"value": "",
"type": "string"
}
]
}
Requirements
- PHP >= 8.2
- Laravel >= 11.0
- Guzzle HTTP Client (for Postman API integration)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.
Author
Mohamed Ayman
Support
If you encounter any issues or have questions, please open an issue on GitHub.
Repository
Changelog
Please see CHANGELOG for more information on what has changed recently.
mohamed-ayman/laravel-postman-generator 适用场景与选型建议
mohamed-ayman/laravel-postman-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「documentation」 「api」 「validation」 「routes」 「middleware」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mohamed-ayman/laravel-postman-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mohamed-ayman/laravel-postman-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mohamed-ayman/laravel-postman-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
Laravel package that generates RESTful API documentation in Markdown based on PHPDoc.
A PSR-7 compatible library for making CRUD API endpoints
Laravel API documentation generating tool
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-09