Download the PHP package jeromejhipolito/laravel-api-versioning without Composer
On this page you can find all versions of the php package jeromejhipolito/laravel-api-versioning. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeromejhipolito/laravel-api-versioning
More information about jeromejhipolito/laravel-api-versioning
Files in jeromejhipolito/laravel-api-versioning
Package laravel-api-versioning
Short Description Header-based API versioning with version flags for Laravel. Supports semantic versioning and feature flag-like version control.
License MIT
Informations about the package laravel-api-versioning
Laravel API Versioning
Header-based API versioning with version flags for Laravel. Supports semantic versioning and feature flag-like version control.
Features
- 🏷️ Header-based versioning - Uses
X-API-Versionheader (industry standard like Stripe, GitHub) - 📦 Semantic versioning - Full support for major.minor.patch format (1.0.0, 1.1.0, 2.0.0)
- 🚩 Version flags - Enable/disable versions independently (perfect for app store review periods)
- 🔒 Minimum version middleware - Require minimum version per route:
min.version:1.1.0 - 🔄 Controller inheritance - Override only changed methods in versioned controllers
- 📱 Mobile-friendly - Disabled versions return
version_enabled: falseso apps can hide features - 🌍 Translations - Built-in support for English, Japanese, and Korean
Installation
Publish Configuration (Optional)
Configuration
Add to your .env:
Edit config/api-versioning.php:
Register Middleware
In bootstrap/app.php:
Usage
Making Requests
Response Headers
Every response includes:
X-API-Version: 1.0.0X-API-Version-Enabled: trueX-API-Supported-Versions: 1.0.0, 1.1.0, 2.0.0X-API-Enabled-Versions: 1.0.0, 1.1.0
Check Version Status
Using in Controllers
Using in Resources
Disabled Version Response
When a version is supported but not enabled:
This allows mobile apps to check version_enabled and hide features accordingly.
Version Flags Workflow
-
Add new version as supported but disabled
-
Deploy to production - Old apps continue working
-
Submit new app version - App checks
version_flagsand hides 2.0.0 features - After app store approval - Enable the version
Minimum Version Middleware
Require a minimum API version for specific routes or groups:
Register the Middleware Alias
In bootstrap/app.php:
Usage
Response When Version Is Too Low
HTTP Status: 400 Bad Request
Available Methods
VersionAwareTrait (Controllers)
| Method | Description |
|---|---|
getApiVersion() |
Get current version string |
getApiMajorVersion() |
Get major version number |
getApiMinorVersion() |
Get minor version number |
getApiPatchVersion() |
Get patch version number |
isVersionAtLeast($v) |
Check if >= version |
isVersionBelow($v) |
Check if < version |
isVersionExactly($v) |
Check if exact version |
isVersionBetween($min, $max) |
Check if in range |
VersionAwareResourceTrait (Resources)
| Method | Description |
|---|---|
mergeWhenVersion($v, $array) |
Merge array if >= version |
mergeWhenVersionBelow($v, $array) |
Merge array if < version |
mergeWhenVersionExactly($v, $array) |
Merge array if exact version |
mergeWhenVersionBetween($min, $max, $array) |
Merge if in range |
whenVersion($v, $value, $default) |
Return value if >= version |
whenVersionBelow($v, $value, $default) |
Return value if < version |
License
MIT License. See LICENSE for details.
All versions of laravel-api-versioning with dependencies
illuminate/support Version ^11.0|^12.0
illuminate/http Version ^11.0|^12.0
illuminate/routing Version ^11.0|^12.0