laravel-api-versioning maintained by pharaonic
Description
Laravel-native API versioning: version groups and constraints on Route, header, query and path resolution, version-specific controllers, and versioned JSON resources.
Author
Last update
2026/11/23 17:47
(dev-develop)
License
Downloads
0
Tags
routing - rest - api - versioning - laravel - sunset - deprecation - api-versioning - json-resources
Installation
composer require pharaonic/laravel-api-versioning
The service provider is registered automatically. Publish the configuration when you need to change it:
php artisan vendor:publish --tag=api-versioning-config
Usage
use App\Http\Controllers\ReportController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\UserV1Controller;
use App\Http\Controllers\UserV2Controller;
// config/pharaonic/api-versioning.php: 'versions' => ['v1', 'v2'],
Route::get('users', [UserController::class, 'index'])->controllers([
'v1' => [UserV1Controller::class, 'index'],
'v2' => [UserV2Controller::class, 'index'],
]);
Route::get('reports', [ReportController::class, 'index'])->sinceVersion('v2');
GET /users with X-API-Version: v2 runs UserV2Controller@index, with its middleware, bindings and policies. No URL prefix is added unless you configure one.
Documentation
Full documentation: API Versioning Documentation.
Support & Security
See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.
License
MIT. See LICENSE.