Search by

yasin_tgh / laravel-postman

yasin.tqvi

A powerful package to automatically generate Postman collections from your Laravel routes with intelligent organization and rich documentation capabilities.

Package info

github.com/yasintqvi/laravel-postman

pkg:composer/yasin_tgh/laravel-postman

Statistics

Installs: 91 579

Dependents: 0

Suggesters: 0

Stars: 330

Open Issues: 0

v1.6.0 2026-11-13 15:09 UTC

README

Turn your Laravel routes into a ready-to-use Postman collection with one command, and keep it in sync.

Latest Version Total Downloads Laravel PHP License

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)prefixcontroller
πŸ“ users
   GET  api/users
   POST api/users
   GET  api/users/:user
   πŸ“ avatar
      POST api/users/:user/avatar
πŸ“ admin
   πŸ“ reports
      πŸ“ export
         GET api/admin/reports/export
πŸ“ users
   GET  api/users
   POST api/users
   GET  api/users/:user
   POST api/users/:user/avatar
πŸ“ admin
   GET api/admin/reports/export
πŸ“ User
   GET  api/users
   POST api/users
   GET  api/users/:user
   POST api/users/:user/avatar
πŸ“ Report
   GET api/admin/reports/export
'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.