yasin_tgh / laravel-postman
A powerful package to automatically generate Postman collections from your Laravel routes with intelligent organization and rich documentation capabilities.
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.2|^8.0
- laravel/framework: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.5|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v1.6.0
- v1.5.0
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.3
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0-beta
- dev-develop
- dev-docs/readme-redesign
- dev-fix/cosmetic-naming-and-auth
- dev-fix/guzzle-8-support
- dev-fix/low-severity-bugs
- dev-fix/medium-severity-bugs
- dev-fix/high-severity-bugs
- dev-fix/custom-validation-rules-53
- dev-fix/union-types-model-binding-46
- dev-fix/optional-before-required-45
This package is auto-updated.
Last update: 2026-11-23 09:42:21 UTC
README
Turn your Laravel routes into a ready-to-use Postman collection with one command, and keep it in sync.
No annotations and no hand-written JSON. Laravel Postman reads your routes and FormRequests and builds the collection your team actually wants to use: organized folders, realistic request bodies and working auth.
β¨ From validation rules to a ready request
Write your validation rules as usual:
class StoreUserRequest extends FormRequest { public function rules(): array { return [ 'email' => 'required|email', 'password' => 'required|string|min:8|confirmed', 'age' => 'required|integer|min:18', 'role' => ['required', Rule::in(['admin', 'editor'])], 'born_at' => 'required|date_format:Y-m-d', 'tags.*' => 'string', 'addresses.*.city' => 'required|string', ]; } }
β¦and get a request body in Postman that passes your own validation:
{
"email": "user89@example.com",
"password": "sample_text",
"password_confirmation": "sample_text",
"age": 27,
"role": "admin",
"born_at": "2026-11-13",
"tags": ["sample_text"],
"addresses": [{ "city": "sample_text" }]
}
Enums, in: lists, number ranges, string lengths, date formats, nested fields, wildcards and confirmed are all understood.
π Quick start
composer require --dev yasin_tgh/laravel-postman php artisan postman:generate
That's it. Import storage/postman/api_collection.json into Postman (File β Import) and start sending requests.
To customize it, publish the config:
php artisan vendor:publish --tag=postman-config
π§° Features
| β‘ Zero-effort docs | Every route under your API prefix, with path variables (:user) and a {{base_url}} variable. |
| π§ͺ Realistic request bodies | Generated from FormRequest rules, as raw JSON or form-data. |
| ποΈ Your folder structure | Group requests by URL path, prefix or controller. |
| π Auth that just works | Bearer, Basic or API key, applied only to protected routes. |
| βοΈ Two-way Postman Cloud sync | Push changes without losing your saved responses, scripts or manual requests. |
| π― Fine-grained filtering | Include or exclude routes by pattern, middleware or controller. |
π Guides
Organize your folders
Pick a strategy in structure.folders.strategy. Here's the same API three ways:
nested_path (default) | prefix | controller |
|---|---|---|
|
|
|
'structure' => [ 'folders' => [ 'strategy' => 'nested_path', // 'nested_path', 'prefix' or 'controller' 'max_depth' => 10, // nested_path only: deeper routes go in the deepest folder ], 'naming_format' => '[{method}] {uri}', // placeholders: {method} {uri} {controller} {action} ],
Choose which routes to document
Only routes under routes.prefix (default api) are included. You can narrow it down further:
'routes' => [ 'prefix' => 'api', 'include' => [ 'patterns' => ['api/users/*'], // wildcards 'middleware' => ['auth:sanctum'], 'controllers' => [UserController::class], ], 'exclude' => [ 'patterns' => ['api/internal/*'], 'middleware' => ['debug'], 'controllers' => [HealthController::class], ], ],
Tip
If a route can't be processed (for example, a missing controller method), it's skipped and listed in the command output with the reason. It never breaks the whole collection.
Shape the request bodies
'structure' => [ 'requests' => [ 'default_body_type' => 'raw', // 'raw' (JSON) or 'formdata' (used for POST) 'default_values' => [ // override generated values by field name 'email' => 'test@example.com', 'password' => 'password', ], ], ],
default_values also fill in path variables. For example, 'user' => 42 sets :user to 42.
Set up authentication
'auth' => [ 'enabled' => true, 'type' => 'bearer', // 'bearer', 'basic' or 'api_key' 'location' => 'header', // api_key only: 'header' or 'query' 'default' => [ 'token' => env('POSTMAN_AUTH_TOKEN'), // bearer 'username' => env('POSTMAN_AUTH_USER'), // basic 'password' => env('POSTMAN_AUTH_PASSWORD'), 'key_name' => 'X-API-KEY', // api_key 'key_value' => env('POSTMAN_AUTH_API_KEY'), ], 'protected_middleware' => ['auth', 'auth:api', 'auth:sanctum'], ],
Routes behind one of the protected_middleware get your auth. Every other route is set to No Auth, so public endpoints never receive your credentials. The values are stored as collection variables ({{auth_token}}, β¦), so you change them in one place.
Warning
Make sure protected_middleware lists the guards your app uses (e.g. auth:sanctum). Otherwise protected routes are generated with No Auth.
βοΈ Sync with Postman Cloud
Keep a shared Postman collection up to date as your API changes, without overwriting the work your team has done in Postman.
1. Add your credentials to .env:
POSTMAN_API_KEY=PMAK-xxxxxxxx # go.postman.co/settings/me/api-keys POSTMAN_COLLECTION_ID=12345678-xxxx # see "Finding your collection ID" below POSTMAN_WORKSPACE_ID= # optional
2. Preview, then push:
php artisan postman:generate --dry-run # show what would change, push nothing php artisan postman:generate --push # merge and push to Postman Cloud
Mergingβ¦
New requests: 2
- POST /api/users
- DELETE /api/users/:user
Updated requests (remote responses, scripts and ids kept): 1
- GET /api/users
Remote-only requests kept: 1
- Status page
[dry-run] Merge complete β no changes pushed to Postman Cloud.
Tip
--dry-run and --push exit with a non-zero code on failure, so you can run them in CI.
What happens on a push
| In Postman | On --push |
|---|---|
| New Laravel routes | β Added to the matching folder |
| Request bodies, headers, URLs of existing routes | π Updated from your code |
| Saved example responses | β
Kept (preserve_responses) |
| Pre-request and test scripts | β
Kept (preserve_scripts) |
| Requests and folders you added by hand | β
Kept (preserve_manual_items) |
| Descriptions written in Postman | β
Kept (overwrite_descriptions: false) |
| Auth set by hand on a public route | β
Kept (protected routes use your auth config) |
| Collection variables | β Kept; new ones are added |
| Requests for deleted or renamed routes | β
Kept by default Β· ποΈ removed with prune_stale_routes: true |
'cloud' => [ 'api_key' => env('POSTMAN_API_KEY'), 'collection_id' => env('POSTMAN_COLLECTION_ID'), 'workspace_id' => env('POSTMAN_WORKSPACE_ID'), 'merge' => [ 'preserve_responses' => true, 'preserve_scripts' => true, 'preserve_manual_items' => true, 'overwrite_descriptions' => false, 'prune_stale_routes' => false, ], ],
Warning
prune_stale_routes removes any remote request whose URL starts with {{base_url}} under your route prefix and has no matching route, including ones you created by hand. Run --dry-run first and check the "Stale requests removed" list.
Finding your collection ID
In the Postman app: open the collection β β― β Info β copy the Collection ID.
With the Postman API: list your collections and copy the uid:
curl -s https://api.getpostman.com/collections -H "X-Api-Key: $POSTMAN_API_KEY" \ | php -r 'foreach (json_decode(stream_get_contents(STDIN), true)["collections"] ?? [] as $c) echo "{$c["name"]} => {$c["uid"]}\n";'
βοΈ Configuration reference
All options in config/postman.php
| Option | Default | Description |
|---|---|---|
name |
APP_NAME |
Collection name |
description |
API_DESCRIPTION |
Collection description |
base_url |
APP_URL |
Value of the {{base_url}} variable |
routes.prefix |
api |
Only routes under this prefix are documented |
routes.include.* / routes.exclude.* |
[] |
Filter by patterns, middleware, controllers |
structure.folders.strategy |
nested_path |
nested_path, prefix or controller |
structure.folders.max_depth |
10 |
Folder depth for nested_path |
structure.naming_format |
[{method}] {uri} |
Request names: {method} {uri} {controller} {action} |
structure.requests.default_body_type |
raw |
raw or formdata |
structure.requests.default_values |
[] |
Fixed values per field or path variable |
auth.enabled |
false |
Add auth to protected routes |
auth.type |
bearer |
bearer, basic or api_key |
auth.location |
header |
Where the API key goes: header or query |
auth.protected_middleware |
auth, auth:api, auth:sanctum |
Middleware that marks a route as protected |
headers |
Accept, Content-Type |
Headers on every request (Content-Type only with raw bodies) |
output.driver |
local |
Filesystem driver (POSTMAN_STORAGE_DISK) |
output.path |
storage/postman |
Output directory (POSTMAN_STORAGE_DIR) |
output.filename |
api_collection |
File name; .json is added if missing (POSTMAN_STORAGE_FILE) |
cloud.* |
β | See Sync with Postman Cloud above |
β FAQ
A route is missing from my collection
Check that it's under routes.prefix and isn't removed by an include/exclude filter. Routes that can't be processed are listed as Skipped in the command output, with the reason.
A request has an empty body
Bodies are generated from a FormRequest type-hinted in the controller method. Plain Request $request parameters and inline $request->validate() calls have no rules to read.
Auth isn't applied to my protected routes
Make sure auth.enabled is true and that auth.protected_middleware contains the exact middleware your routes use, e.g. auth:sanctum.
π€ Contributing
Pull requests are welcome! For major changes, please open an issue first.
composer install
composer test
π License
MIT. See LICENSE.