- yasin_tgh/laravel-postman v1.3
- Documentation: https://github.com/yasintqvi/laravel-postman
The package automatically extracts validation rules from FormRequest classes and generates sample request bodies.
How it works:
- Package reads
rules()method from FormRequest - Automatically generates example values based on validation rules:
email→user12@example.comnumeric→ Random number within min/maxstring→"field_name sample value"boolean→trueorfalse
The package has been extended with automatic query parameter detection! 🎉
The custom QueryParameterExtractor service automatically detects query parameters by:
- Pagination Detection: Scans controller methods for
->paginate(),->simplePaginate(), or->cursorPaginate()calls - Query Parameter Detection: Finds
$request->query(),$request->get(), or$request->input()calls in GET methods - Auto-Generation: Adds them to the Postman collection with proper structure
public function index()
{
$products = Product::query()->paginate(10); // ← Automatically detected!
return response()->json($products);
}Generated Query Params:
page=1- Page number for paginationper_page=10- Items per page
public function download($tenantId, Request $request)
{
$filename = $request->input('file'); // ← Automatically detected!
// ...
}Generated Query Param:
file=- File (empty default value)
The following GET endpoints automatically have query parameters:
-
GET /api/products
- ✅
page=1 - ✅
per_page=10
- ✅
-
GET /api/central/tenants
- ✅
page=1(if pagination is used) - ✅
per_page=10(if pagination is used)
- ✅
-
GET /api/central/tenants/{id}/backups/download
- ✅
file=(detected from$request->input('file'))
- ✅
Files Created:
app/Services/QueryParameterExtractor.php- Scans controllers for pagination and query paramsapp/Services/ExtendedRouteGrouper.php- Extends package's RouteGrouper with query param supportapp/Providers/PostmanExtensionServiceProvider.php- Registers custom services
How to Use:
php artisan postman:generateThat's it! Query parameters are automatically detected and added. ✨
If you want to add more query parameters manually, just use them in your GET controllers:
public function index(Request $request)
{
$search = $request->query('search'); // ← Will be detected
$sortBy = $request->get('sort_by'); // ← Will be detected
$order = $request->input('order'); // ← Will be detected
$results = Model::query()
->when($search, fn($q) => $q->where('name', 'like', "%{$search}%"))
->orderBy($sortBy ?? 'id', $order ?? 'asc')
->paginate(10); // ← Pagination detected
return response()->json($results);
}Then regenerate:
php artisan postman:generateQuery params will include: page, per_page, search, sort_by, order
- Bearer Token: Auto-added to protected routes (routes with
auth:sanctummiddleware) - API Keys: Added to all requests
X-Tenant-API-Keyfor tenant routesX-Master-API-Keyfor central routes
{{base_url}}- Your app URL{{auth_token}}- Bearer token (set after login)- Environment variables in .env:
POSTMAN_AUTH_TOKENPOSTMAN_TENANT_API_KEYPOSTMAN_MASTER_API_KEY
Routes are automatically grouped by controller for clean, efficient structure:
Laravel Multi-Tenant API
├── ⚙️ System Routes (debug, info - closure routes)
├── 🏢 Tenant Management (CRUD, health check, test connection)
├── 💾 Backup & Restore (backup, restore, download, stats)
├── 🔐 Authentication (register, login, logout, me)
└── 📦 Products (CRUD operations)
Before (deeply nested):
central/
debug/
tenants/
[GET] api/central/debug/tenants
tenants/
[POST] api/central/tenants
...
After (flat, efficient):
🏢 Tenant Management/
[POST] api/central/tenants
[GET] api/central/tenants
[GET] api/central/tenants/{id}
...
php artisan postman:generateOutput: storage/postman/api_collection
- Open Postman
- Click Import button
- Select
storage/postman/api_collection - Done! ✅
php artisan make:request YourRequest<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class YourRequest extends FormRequest
{
public function authorize(): bool
{
return true; // ⚠️ IMPORTANT: Set to true
}
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'email' => 'required|email',
'age' => 'required|numeric|min:18|max:100',
'is_active' => 'boolean',
];
}
}use App\Http\Requests\YourRequest;
public function store(YourRequest $request)
{
// Package will auto-detect this and generate body
$data = $request->validated();
// Your logic...
}php artisan postman:generateAuto-generated body will be:
{
"name": "name sample value",
"email": "user42@example.com",
"age": 25,
"is_active": true
}Edit config/postman.php:
'routes' => [
'prefix' => 'api',
'include' => [
'middleware' => ['api', 'tenant'], // Only include routes with these middleware
],
'exclude' => [
'patterns' => ['api/_ignition/*'], // Exclude debug routes
],
],'auth' => [
'enabled' => true,
'type' => 'bearer',
'protected_middleware' => ['auth:sanctum', 'auth:api', 'tenant.token'],
],'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'X-Tenant-API-Key' => '',
'X-Master-API-Key' => env('MASTER_API_KEY'),
],{
"name": "name sample value",
"email": "user47@example.com",
"password": "password",
"password_confirmation": "password",
"role": "role sample value"
}{
"name": "name sample value",
"db_host": "db_host sample value",
"db_port": 3306,
"db_name": "db_name sample value",
"db_username": "db_username sample value",
"db_password": "db_password sample value"
}{
"name": "name sample value",
"description": "description sample value",
"price": 50
}- Always use FormRequests instead of
$request->validate()for auto-generation - Set
authorize()totruein FormRequests - Use descriptive validation rules for better sample data
- Regenerate after adding new routes with
php artisan postman:generate - Commit the collection to git for team collaboration
- ✅ Check if you're using FormRequest (not
Validator::make()) - ✅ Ensure
authorize()returnstrue - ✅ Verify route is not excluded in config
- ✅ Check
config/postman.phpheaders section - ✅ Ensure routes match the middleware filters
- ✅ Set
POSTMAN_AUTH_TOKENin.envafter login - ✅ Check
protected_middlewarein config matches your routes
'structure' => [
'requests' => [
'default_body_type' => 'raw', // or 'formdata'
]
],'structure' => [
'folders' => [
'strategy' => 'nested_path', // 'prefix', 'nested_path', or 'controller'
'max_depth' => 5,
],
],'structure' => [
'naming_format' => '[{method}] {uri}', // Placeholders: {method}, {uri}, {controller}, {action}
],You now have:
- ✅ Automatic request body generation from validation rules
- ✅ Bearer token authentication on protected routes
- ✅ API key headers (tenant + master)
- ✅ Collection variables for easy configuration
- ✅ Sample data based on your validation rules
Just run php artisan postman:generate after any route changes!