PHPackages                             hopheartsceo/laravel-postman-exporter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. hopheartsceo/laravel-postman-exporter

ActiveLibrary[API Development](/categories/api)

hopheartsceo/laravel-postman-exporter
=====================================

Automatically generate Postman v2.1 collections from your Laravel application routes, controllers, and FormRequest validations.

v1.1.0(4mo ago)357MITPHPPHP ^8.1

Since Mar 8Pushed 4mo agoCompare

[ Source](https://github.com/hopheartsceo/Laravel-Postman-Exporter)[ Packagist](https://packagist.org/packages/hopheartsceo/laravel-postman-exporter)[ RSS](/packages/hopheartsceo-laravel-postman-exporter/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (8)Versions (4)Used By (0)

Laravel Postman Exporter
========================

[](#laravel-postman-exporter)

[![Laravel](https://camo.githubusercontent.com/36ab9eb40d419c375ec1c19e6d5fd0d5ae0aeb01372cc6b164966c412feecdad/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532422d7265642e737667)](https://laravel.com)[![PHP](https://camo.githubusercontent.com/7535257ca228724c93658bd52583d4e47a9bab02c356abf6e54c1d575f2151e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Automatically generate **Postman Collection v2.1** files and **OpenAPI 3.0** specifications from your Laravel application routes, controllers, and FormRequest validations — complete with **hierarchical folder grouping** and **response examples**.

---

✨ Features
----------

[](#-features)

- 🔍 **Route Scanning** — Automatically reads all registered API routes
- 📝 **Request Analysis** — Extracts validation rules from FormRequest classes and inline `$request->validate()` calls
- 🎯 **Smart Example Data** — Generates realistic sample values based on validation rules and field names
- 🔐 **Authentication Detection** — Automatically adds auth headers based on middleware (Sanctum, Passport, etc.)
- 📁 **Hierarchical Grouping** — Organizes requests into nested folders based on route prefixes
- 📋 **Response Examples** — Extracts response structures from PHPDoc, API Resources, `response()->json()`, and Eloquent models
- 📄 **OpenAPI Support** — Export your API as a valid OpenAPI 3.0.3 specification
- 🚀 **Postman Upload** — Optionally upload collections directly via the Postman API
- ⚡ **Artisan Command** — Beautiful CLI with progress indicators and colored output

---

📦 Installation
--------------

[](#-installation)

You can install the package via composer:

```
composer require hopheartsceo/laravel-postman-exporter --dev
```

### Installation from GitHub (Development)

[](#installation-from-github-development)

If you haven't published to Packagist yet, add this to your `composer.json`:

```
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/hopheartsceo/laravel-postman-exporter"
    }
],
"require": {
    "hopheartsceo/laravel-postman-exporter": "dev-main"
}
```

Publish the configuration file:

```
php artisan vendor:publish --tag=postman-exporter-config
```

---

🚀 Usage
-------

[](#-usage)

### Artisan Command

[](#artisan-command)

```
# Export as Postman Collection (default)
php artisan postman:export

# Export as OpenAPI 3.0 specification
php artisan postman:export --format=openapi

# Custom output path
php artisan postman:export --output=./docs/api-spec.json

# Group routes by prefix (works for both formats)
php artisan postman:export --group-by-prefix

# Include response examples (Postman only currently)
php artisan postman:export --with-responses
```

### Facade API

[](#facade-api)

```
use Hopheartsceo\PostmanExporter\Facades\PostmanExporter;

// Generate Postman Collection (default)
$collection = PostmanExporter::generate();

// Generate OpenAPI spec
$openapi = PostmanExporter::generate('openapi');

// Generate and save to file
$path = PostmanExporter::save('/path/to/collection.json');

// Generate and upload to Postman
$result = PostmanExporter::upload('your-api-key');
```

---

⚙️ Configuration
----------------

[](#️-configuration)

After publishing, edit `config/postman-exporter.php`:

OptionTypeDefaultDescription`base_url`string`env('APP_URL')`Base URL for all requests`default_headers`arrayAccept + Content-Type JSONDefault headers on every request`output_path`string`storage/app/postman-collection.json`Default output path`collection_name`stringApp name + " API Collection"Name of the Postman collection`grouping`array(see below)Folder grouping configuration`responses`array(see below)Response examples configuration`include_web_routes`bool`false`Include non-API routes`postman_api_key`string`''`Postman API key for uploads`enable_upload`bool`false`Auto-upload after generation### Folder Grouping

[](#folder-grouping)

Routes are grouped into **flat, single-level folders** by the first segment of the URI. No nesting is created — every route belongs to exactly one top-level folder.

```
'grouping' => [
    'enabled'         => true,
    'strategy'        => 'prefix',      // Only 'prefix' strategy supported
    'fallback_folder' => 'general',     // Folder for unprefixed / root routes
],
```

**How it works:**

URIFolder`api/users``api``api/users/{id}``api``auth/login``auth``auth/logout``auth``status``general` (fallback)`/{id}``general` (fallback)- The first segment of the URI (`explode('/', $uri)[0]`) becomes the folder name.
- Routes whose first segment is empty or a parameter (e.g. `{id}`) go to the **fallback folder**.
- There are **no root-level requests** — every request lives inside a folder.
- There are **no nested folders** — the structure is always flat.

### Response Examples

[](#response-examples)

Response examples are extracted automatically from your controller methods and attached to each Postman request item.

```
'responses' => [
    'enabled'         => true,
    'fallback_status' => 200,
    'fallback_body'   => ['message' => 'Success'],
],
```

Or enable at export time with the `--with-responses` flag:

```
php artisan postman:export --with-responses
```

**Extraction priority (highest to lowest):**

1. **PHPDoc `@response`** — Parses `@response` tags with optional status codes:

    ```
    /**
     * @response 200 {"id": 1, "name": "John Doe"}
     * @response {"data": []}
     */
    public function index() { ... }
    ```
2. **API Resource** — Detects `return new UserResource(...)` patterns and reads the Resource's `$fillable`/`$visible` fields.
3. **`response()->json()`** — Parses inline `response()->json([...], 200)` calls to extract the body and status code.
4. **Eloquent Model** — Detects `return User::find(...)` patterns and generates example data from the model's `$fillable` fields.
5. **Fallback** — Uses the configured `fallback_status` and `fallback_body`.

**Generated response format in Postman:**

```
{
    "response": [
        {
            "name": "Success Response",
            "originalRequest": { "method": "GET", "url": { ... } },
            "status": "OK",
            "code": 200,
            "_postman_previewlanguage": "json",
            "header": [
                { "key": "Content-Type", "value": "application/json" }
            ],
            "body": "{\"id\": 1, \"name\": \"John Doe\"}"
        }
    ]
}
```

### Route Filters

[](#route-filters)

```
'route_filters' => [
    'include_prefixes'  => [],              // Only include these prefixes
    'exclude_prefixes'  => ['_ignition'],   // Exclude these prefixes
    'include_middleware' => [],              // Only include routes with these middleware
    'exclude_middleware' => [],              // Exclude routes with these middleware
],
```

### Middleware to Headers Map

[](#middleware-to-headers-map)

```
'middleware_to_headers_map' => [
    'auth:sanctum' => [
        'Authorization' => 'Bearer {{token}}',
    ],
    'auth:api' => [
        'Authorization' => 'Bearer {{token}}',
    ],
],
```

---

📄 Example Output
----------------

[](#-example-output)

The generated collection follows the [Postman Collection v2.1 schema](https://schema.getpostman.com/json/collection/v2.1.0/collection.json). Folders are flat (single-level) and each request includes response examples:

```
{
    "info": {
        "name": "My App API Collection",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "item": [
        {
            "name": "api",
            "item": [
                {
                    "name": "users.index",
                    "request": {
                        "method": "GET",
                        "url": {
                            "raw": "{{base_url}}/api/users",
                            "host": ["{{base_url}}"],
                            "path": ["api", "users"]
                        },
                        "header": [
                            { "key": "Accept", "value": "application/json" },
                            { "key": "Authorization", "value": "Bearer {{token}}" }
                        ]
                    },
                    "response": [
                        {
                            "name": "Success Response",
                            "originalRequest": {
                                "method": "GET",
                                "url": {
                                    "raw": "{{base_url}}/api/users",
                                    "host": ["{{base_url}}"],
                                    "path": ["api", "users"]
                                }
                            },
                            "status": "OK",
                            "code": 200,
                            "_postman_previewlanguage": "json",
                            "header": [
                                { "key": "Content-Type", "value": "application/json" }
                            ],
                            "body": "{\"data\": [{\"id\": 1, \"name\": \"John Doe\"}]}"
                        }
                    ]
                }
            ],
            "description": "Routes for api"
        },
        {
            "name": "general",
            "item": [
                {
                    "name": "GET Status",
                    "request": {
                        "method": "GET",
                        "url": {
                            "raw": "{{base_url}}/status",
                            "host": ["{{base_url}}"],
                            "path": ["status"]
                        }
                    },
                    "response": [
                        {
                            "name": "Success Response",
                            "originalRequest": {
                                "method": "GET",
                                "url": {
                                    "raw": "{{base_url}}/status",
                                    "host": ["{{base_url}}"],
                                    "path": ["status"]
                                }
                            },
                            "status": "OK",
                            "code": 200,
                            "_postman_previewlanguage": "json",
                            "header": [
                                { "key": "Content-Type", "value": "application/json" }
                            ],
                            "body": "{\"message\": \"Success\"}"
                        }
                    ]
                }
            ],
            "description": "Routes for general"
        }
    ],
    "variable": [
        { "key": "base_url", "value": "http://localhost" },
        { "key": "token", "value": "your-auth-token-here" }
    ]
}
```

> See [`examples/sample-collection.json`](examples/sample-collection.json) for a full example with multiple folders and response examples.

---

🧪 Testing
---------

[](#-testing)

```
composer test
# or
vendor/bin/phpunit
```

---

🏗️ Architecture
---------------

[](#️-architecture)

ServiceResponsibility`RouteScannerService`Scans Laravel routes via the Router; extracts return types, PHPDoc, and API Resource usage`RequestAnalyzerService`Extracts FormRequest/inline validation rules`ValidationParserService`Parses validation rules into structured format`ExampleDataGeneratorService`Generates realistic sample values`FolderOrganizerService`Groups routes into flat, single-level folders by first URI segment`ResponseExtractorService`Analyzes controller methods to extract response structures (PHPDoc → API Resource → JSON → Model → Fallback)`ExampleResponseGeneratorService`Converts extracted response data into Postman-formatted response arrays`PostmanCollectionBuilderService`Builds Postman v2.1 JSON structure with folders and response examples`PostmanUploaderService`Uploads collections to Postman API---

📋 Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Laravel 10, 11, or 12

---

📝 License
---------

[](#-license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance74

Regular maintenance activity

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

2

Last Release

149d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec80bdead360836c93f7382e6fd1b330f59e689791124494785a582ce02cb99a?d=identicon)[hopheartsceo](/maintainers/hopheartsceo)

---

Top Contributors

[![hopheartsceo](https://avatars.githubusercontent.com/u/78211358?v=4)](https://github.com/hopheartsceo "hopheartsceo (7 commits)")

---

Tags

apilaravelroutesgeneratorexportercollectionPostman

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hopheartsceo-laravel-postman-exporter/health.svg)

```
[![Health](https://phpackages.com/badges/hopheartsceo-laravel-postman-exporter/health.svg)](https://phpackages.com/packages/hopheartsceo-laravel-postman-exporter)
```

###  Alternatives

[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M211](/packages/laravel-mcp)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k31.8M158](/packages/laravel-cashier)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M146](/packages/roots-acorn)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
