jdlxnl / api-version
Add version as prefix to routes and make it available through a facade in Laravel
1.0.0
2021-12-23 10:23 UTC
Requires
- illuminate/http: ^8.77
- illuminate/support: ^8.77
This package is auto-updated.
Last update: 2025-02-23 18:04:11 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);