PHP code example of dongivan / laravel-route-versioning

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

    

dongivan / laravel-route-versioning example snippets



// api.php

use \Illuminate\Support\Facades\Route;

Route::version(1)->get("users", [App\Http\Controllers\UsersController::class, "index"])->name("v1:users.index");

Route::version("v2.1")->get("users", [App\Http\Controllers\V2_1\UsersController::class, "index"])->name("v2.1:users.index");

Route::version("v1")->name("v1:posts.")->group(function() {
    Route::get("posts", [App\Http\Controllers\PostsController::class, "index"])->name("index")
    Route::post("posts", [App\Http\Controllers\PostsController::class, "store"])->name("store")
    Route::put("posts/{post}", [App\Http\Controllers\PostsController::class, "update"])->name("update")
});

Route::version("v2")->group(function() {
    Route::resource("comments", App\Http\Controllers\V2\CommentsController::class)->only(["store", "index"]);
})



return [
    "headerKey" => "X-VERSION",
    "strict" => false,
];