If you ship APIs with Laravel, you know just how much of a pain it is to try and keep your Postman workspace in sync. Add one new endpoint, rename a route, or slightly change a URL, and suddenly tests fail or your teammates use requests that are outdated. With the right workflow, you can instantly generate Postman Collections from Laravel Routes and keep everything up to date with almost zero manual effort.
With a small, focused Laravel Postman Collection Generator package, you can automatically generate your Postman collection from Laravel in seconds. Instead of tediously hand-crafting each and every request, you let Laravel’s routing layer speak straight to Postman. Save time, avoid mistakes, and keep your API consumers happy.
Why Automate Postman Collections?
For very small APIs, it’s fine to create a Postman collection manually. As the project grows, it becomes very hard to manage. Every new route means creating a new request, choosing a method, probably changing a URL, maybe headers, a body, and authentication, which can easily result in mistakes or forgotten changes.
When you create a Postman collection from existing Laravel routes, Laravel becomes the single source of truth. The package reads your routes and exports them to Postman in one step, saving time, reducing errors, and giving everyone an always up‑to‑date collection.
Main Benefits of the yasintqvi Laravel Postman Package
The yasintqvi Laravel Postman package offers a clean, code‑driven way to create collections. Among its main advantages are:
- Generate a full Postman collection from your Laravel routes with one artisan command
- Keep collections in sync with your routes any time the API changes
- Filter routes by prefix or pattern to include only the relevant API endpoints.
- Apply global authentication and headers across every generated request
- Export standard Postman JSON that any team member can import instantly
Installing and Configuring the Package
You should install the package as a dev dependency so it stays tied to your project without affecting production logic. Run the following command inside your Laravel project:
composer require --dev yasintqvi/laravel-postman
After installation, publish the configuration file so you can customize how the generator behaves:
php artisan vendor:publish --provider="Yasintqvi\LaravelPostman\LaravelPostmanServiceProvider"
This command creates a config file, usually config/postman.php. Open that file and adjust the basic settings, such as collection name, description, base URL, and output path. For example:
return [
'name' => 'My App API',
'description' => 'Postman collection for My App API routes',
'base_url' => env('APP_URL', 'http://localhost'),
'output' => storage_path('app/postman/collection.json'),
'routes' => [
'include' => ['api*'],
'exclude' => [],
],
'auth' => [
'enabled' => false,
'type' => 'bearer',
'token' => env('POSTMAN_API_TOKEN'),
],
'headers' => [
'Accept' => 'application/json',
],
];
In a typical setup, you include only api routes, set the base URL from APP_URL, and define where the Postman JSON file should be stored. You can tweak these values later without touching your controllers or route files.
Exporting API Routes to Postman Collection
Once you configure the package, you can convert Laravel routes to Postman JSON with a single artisan command. The command usually looks like this:
php artisan postman:generate
When you run it, the package scans your defined routes, applies your include and exclude rules, and then exports a Postman collection file to the output path in your config. For example, you might end up with storage/app/postman/collection.json.
{
"info": {
"name": "codewolfy.com API",
"_postman_id": "c5a7a7e0-1234-4a8f-9f0e-9b2a1c0d9f01",
"description": "Minimal sample Postman collection for codewolfy.com",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"variable": [
{
"key": "base_url",
"value": "https://codewolfy.com"
}
],
"item": [
{
"name": "List Posts",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{base_url}}/api/posts",
"host": [
"{{base_url}}"
],
"path": [
"api",
"posts"
]
}
}
},
{
"name": "Create Post",
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\"title\":\"Sample title\",\"content\":\"Sample content\"}"
},
"url": {
"raw": "{{base_url}}/api/posts",
"host": [
"{{base_url}}"
],
"path": [
"api",
"posts"
]
}
}
}
]
}
You can now open Postman, click “Import,” and select that JSON file. Postman will create a new collection with all your API endpoints. Every route that matches your config appears as a request with the correct HTTP method and URL. You have just used your existing routes to export Laravel API routes to Postman without writing a single manual request.
Customization Options
You can fine‑tune the generated collection so it reflects how your API works in real life. The configuration file gives you several powerful levers.
Excluding Certain Routes
Let’s take an common configuration need like while generating postman collection sometimes we need to skip some endpoints. For example, admin panel endpoints, tools or package endpoints like horizon or telescope, or debug endpoints.
To keep those out, adjust the routes section in config/postman.php:
'routes' => [
'include' => ['api*'],
'exclude' => [
'telescope*',
'horizon*',
'admin*',
],
],
Handling API Authentication
Most APIs require authentication, and your Postman collection should reflect that. Instead of adding tokens to each request manually, you can configure global auth in the package settings. A simple Bearer token setup might look like this:
'auth' => [
'enabled' => true,
'type' => 'bearer',
'token' => env('POSTMAN_API_TOKEN'),
],
You then add POSTMAN_API_TOKEN to your .env file. The package injects this token into every generated request, so your collection is ready to use immediately.
Conclusion
Keeping Postman in sync manually with a growing Laravel codebase burns time and creates confusion. By generating Postman Collections from Laravel Routes, you use your existing routing layer as the master record and let a tool do the repetitive work. In this recipe, you learned how to install the package, configure it for your project, and run a simple command in order to automatically generate Postman collection from Laravel. Also, you saw how to exclude internal routes, handle API authentication, and customize names, URLs, and headers so that the collection matches your real‑world needs.
