1. Go to this page and download the library: Download jdlxnl/api-version library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jdlxnl / api-version example snippets
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)){
}
// 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);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.