jdlxnl / api-version
Add version as prefix to routes and make it available through a facade in Laravel
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/jdlxnl/api-version
Requires
- illuminate/http: ^8.77
- illuminate/support: ^8.77
This package is auto-updated.
Last update: 2025-09-23 19:08:01 UTC
README
Enables you to create an API version prefix, and make it available in your code.
After installation you can:
use Jdlx\ApiVersion\Facade\Version; // get current version number as int Version::number(); // Do something only for request to the old api if(Version::before(2)){ } // Do something only for request to the new api if(Version::from(2)){ }
Installation
composer require jdlxnl/api-version
Register the Facade
// app/Http/kernel.php // Add api midleware protected $middlewareGroups = [ 'api' => [ SetApiVersion::class, ], ]; // app/Config/app.php 'providers' => [ ... App\Library\ApiVersion\Provider\ApiVersionServiceProvider::class ] // change base path for swagger // app/Http/Documentation/Server // Add the option to the router // routes/api.php $apiRoutes = function () { // define routes }; Route::group(['prefix' => '{version?}', 'where' => ['version' => 'v[0-9]+']], $apiRoutes);