PHP code example of tenantcloud / laravel-api-versioning

1. Go to this page and download the library: Download tenantcloud/laravel-api-versioning 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/ */

    

tenantcloud / laravel-api-versioning example snippets


// Api-Version: 1.0 -> CacToolCampaignController
// Api-Version: latest -> CacToolCampaignController
Route::post('cac/campaigns', [CacToolCampaignController::class, 'create']);

// Api-Version: 4.0 -> 404
// Api-Version: 3.0 -> CacToolCampaignTemplateController
// Api-Version: 1.0 -> CacToolCampaignTemplateController
Route::get('cac/campaigns/template', CacToolCampaignTemplateController::class)
->versioned('<=3.0');

// Api-Version: 3.0 -> CacToolCampaignTemplateController
// Api-Version: 4.0 -> CacToolCampaignTemplateForNewVersionController
// Api-Version: latest -> CacToolCampaignTemplateForNewVersionController
Route::get('cac/campaigns/template', CacToolCampaignTemplateController::class)
->versioned('<=3.0')
->versioned('>=4.0', [CacToolCampaignTemplateForNewVersionController::class, 'index'])

// Api-Version: 3.0 -> CacToolCampaignTemplateController
// Api-Version: 4.0 -> error
// Api-Version: 5.0 -> CacToolCampaignVersion5Controller
// Api-Version: latest -> CacToolCampaignVersion5Controller
Route::get('cac/campaigns/template', CacToolCampaignTemplateController::class)
->versioned('<=3.0')
->versioned('>=5.0', [CacToolCampaignVersion5Controller::class, 'index'])