PHPackages                             uttamrabadiya/api-version-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. uttamrabadiya/api-version-manager

ActiveLibrary[API Development](/categories/api)

uttamrabadiya/api-version-manager
=================================

Simplify Laravel API versioning with ease. No more separate controllers—just flexibility, fallbacks, and version-specific components.

0.3.0(2y ago)13648MITPHP

Since Dec 22Pushed 2y ago3 watchersCompare

[ Source](https://github.com/uttamrabadiya/api-version-manager)[ Packagist](https://packagist.org/packages/uttamrabadiya/api-version-manager)[ Docs](https://github.com/uttamrabadiya/api-version-manager)[ RSS](/packages/uttamrabadiya-api-version-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Laravel API Version Manager
===========================

[](#laravel-api-version-manager)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)[![Latest Version on Packagist](https://camo.githubusercontent.com/294b8e5e899fc44cef4830d4b5dcc77ad5581869db28538e76f97b3bac5927f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f757474616d72616261646979612f6170692d76657273696f6e2d6d616e616765722e737667)](https://packagist.org/packages/uttamrabadiya/api-version-manager)[![GitHub Tests Action Status](https://camo.githubusercontent.com/24ca3c6267c5d6200df89f3f916acd763c27aac6e6ddb357cf5a2dd4878f7c20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f757474616d72616261646979612f6170692d76657273696f6e2d6d616e616765722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/uttamrabadiya/api-version-manager/actions?query=workflow%3Atests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/64fb5c103159cf720d73477de94268c5183ae34daee18528bd7aea61ff2fc70e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f757474616d72616261646979612f6170692d76657273696f6e2d6d616e616765722e737667)](https://packagist.org/packages/uttamrabadiya/api-version-manager)

The **Laravel API Version Manager** Package streamlines the management of API endpoint versions in Laravel applications. This package empowers you to effortlessly handle API versioning, eliminating the necessity to create individual controllers for each version. Its design presents a flexible and efficient solution, enabling you to define fallback versions and effortlessly generate version-specific Requests and Resources.

Features
--------

[](#features)

- **Fallback Versions**: Define fallback versions for your API routes, ensuring smooth transitions and maintaining backward compatibility.
- **Single Controller**: Eliminate the need to create separate controllers for each API version. Our package dynamically injects version-specific Request and Resource classes into your existing controller.
- **Effortless Versioning**: Easily manage API versions through route configuration. The package automatically handles the resolution of version-specific components, streamlining your development process.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require uttamrabadiya/api-version-manager
```

Configuration
-------------

[](#configuration)

### Publish Config File

[](#publish-config-file)

It is mandatory to publish the config file before using the package. You can publish the config file using the following command:

```
php artisan vendor:publish --tag=api-version-manager
```

### Mandatory Configurations:

[](#mandatory-configurations)

- Define available `versions` array in config
- Define default version `version` in config

### Other possible configurations are:

[](#other-possible-configurations-are)

- `app_http_namespace` (default: `App\Http`) - Generally we use `App\Http` namespace to store all our requests &amp; resources classes, but if you are using different namespace then you can define it here.
- `api_prefix` (default: `api`) - API prefix for all versioned routes.
- `use_fallback_entity` (default: `true`) - If you want to use fallback entity for all request &amp; resource class then set this to `true`, otherwise set it to `false`. For example, you define `SampleRequest` in **V1**, and now you want to use same request in **V2** then you can set this option to `true` and it will automatically use `SampleRequest` from **V1**.

Available Commands
------------------

[](#available-commands)

#### Create a new versioned request

[](#create-a-new-versioned-request)

```
php artisan make:versioned-request {name}
```

**Possible options:**

- `--force`: Overwrite the request if it already exists.

#### Create a new versioned resource

[](#create-a-new-versioned-resource)

```
php artisan make:versioned-resource {name}
```

**Possible options:**

- `--collection`: Create a resource collection instead of a single resource.
- `--force`: Overwrite the resource if it already exists.

Usage
-----

[](#usage)

Example of `api.php` file:

```
Route::prefix('v1')->group(function () {
    Route::get('endpoint1', [SomeController::class, 'endpoint1']); // Available on v1 & v2 (Via default fallback)
    Route::get('endpoint2', [SomeController::class, 'endpoint2']); // Available on v1 & v2 (Via default fallback)
});
Route::prefix('v2')->group(function () {
    Route::get('new-endpoint', [SomeController::class, 'endpoint3']); // Available only on v2
});
```

Example of `SomeController.php` file:

```
