Generate a Postman Collection v2.1 from your Laravel API routes — with a single Artisan command.
Annotate your controllers with simple PHPDoc tags to control authentication, headers, descriptions, and even Postman pre-request and test scripts. The output is a ready-to-import JSON collection — no manual route copying, no drift between code and docs.
- 🚀 One-command export —
php artisan postman:exportand you're done - 🔐 Auth support — Bearer tokens, no-auth, parent-inherited, per-endpoint
- 📝 Rich annotations — descriptions, headers, scripts via standard PHPDoc
- 📂 External file sources — load descriptions and scripts from
base_path()orresource_path() - ⚡ Pre-request & test scripts — inject Postman JavaScript directly from your code
- 🎯 Folder grouping — collections organized by route prefix
- 🧩 Laravel 6 → 12 — broad compatibility, PHP 7.1+ through 8.x
- PHP 7.1 or higher
- Laravel 6.x — 12.x
composer require oooiik/laravel-export-postmanPublish the config (optional):
php artisan vendor:publish --provider="Oooiik\LaravelExportPostman\ExportPostmanServiceProvider"Export your routes to a Postman collection:
php artisan postman:exportThe collection file will be created in your configured storage path. Import it into Postman → File → Import.
Edit config/export-postman.php after publishing:
return [
'name' => env('APP_NAME', 'Laravel API'),
'output_path' => storage_path('app/postman'),
'base_url' => env('APP_URL', 'http://localhost'),
// ... and more
];Add PHPDoc annotations to your controller methods or closures to enrich the generated collection.
| Annotation | Description |
|---|---|
@AuthNo |
No authentication for this endpoint |
@AuthParent |
Inherit authentication from the parent folder |
@AuthBearer [token] |
Use a Bearer token (literal value or Postman variable) |
/**
* @AuthBearer {{access_token}}
*/
public function show($id) { /* ... */ }Use @Header key => value for custom request headers. Multiple @Header annotations are supported.
/**
* @Header Accept => application/json
* @Header X-Tenant-Id => {{tenant_id}}
*/
public function index() { /* ... */ }Three flavors — inline, file from base_path(), file from resource_path(). They can be combined.
| Annotation | Source |
|---|---|
@DescriptionContext [text] |
Inline markdown text |
@DescriptionBasePath [path] |
File path relative to base_path() |
@DescriptionResourcePath [path] |
File path relative to resource_path() |
/**
* @DescriptionContext Returns a paginated list of orders for the authenticated user.
* @DescriptionResourcePath docs/api/orders-index.md
*/
public function index() { /* ... */ }Inject Postman JavaScript that runs before the request is sent. Useful for token refresh, signature generation, or dynamic variables.
| Annotation | Source |
|---|---|
@PreRequestScriptContext [js] |
Inline JavaScript |
@PreRequestScriptFileBasePath [path] |
JS file relative to base_path() |
@PreRequestScriptFileResourcePath [path] |
JS file relative to resource_path() |
/**
* @PreRequestScriptFileResourcePath postman/scripts/refresh-token.js
*/
public function transfer() { /* ... */ }Inject Postman JavaScript that runs after the response is received. Use for assertions or extracting values into environment variables.
| Annotation | Source |
|---|---|
@TestScriptContext [js] |
Inline JavaScript |
@TestScriptFileBasePath [path] |
JS file relative to base_path() |
@TestScriptFileResourcePath [path] |
JS file relative to resource_path() |
/**
* @TestScriptContext pm.test("Status 200", () => pm.response.to.have.status(200));
*/
public function login() { /* ... */ }/**
* @AuthBearer {{access_token}}
* @Header Accept => application/json
* @Header X-Tenant-Id => {{tenant_id}}
* @DescriptionContext Creates a new order for the authenticated user.
* @DescriptionResourcePath docs/api/orders-create.md
* @PreRequestScriptFileResourcePath postman/scripts/sign-request.js
* @TestScriptContext pm.test("Created", () => pm.response.to.have.status(201));
*/
public function store(StoreOrderRequest $request)
{
// ...
}| Laravel | PHP | Status |
|---|---|---|
| 12.x | 8.2+ | ✅ Supported |
| 11.x | 8.2+ | ✅ Supported |
| 10.x | 8.1+ | ✅ Supported |
| 9.x | 8.0+ | ✅ Supported |
| 8.x | 7.3+ | ✅ Supported |
| 7.x | 7.2.5+ | ✅ Supported |
| 6.x | 7.2+ | ✅ Supported |
Pull requests are welcome. For larger changes, please open an issue first to discuss the direction.
Feature ideas, bug reports, and questions → GitHub Issues.
- Obidjon Toshev — author & maintainer
- All contributors
The MIT License (MIT). See LICENSE for details.