PHPackages                             philiprehberger/laravel-api-versioning - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. philiprehberger/laravel-api-versioning

ActiveLibrary[HTTP &amp; Networking](/categories/http)

philiprehberger/laravel-api-versioning
======================================

Laravel middleware for API versioning with multi-source resolution from headers, Accept vendor types, and URL path segments

v1.0.4(1mo ago)116[1 PRs](https://github.com/philiprehberger/laravel-api-versioning/pulls)MITPHPPHP ^8.2CI passing

Since Mar 6Pushed 1mo agoCompare

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

READMEChangelogDependencies (9)Versions (6)Used By (0)

Laravel API Versioning
======================

[](#laravel-api-versioning)

[![Tests](https://github.com/philiprehberger/laravel-api-versioning/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/laravel-api-versioning/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/781dc0064b345bee6f752727bd6d898e6bce342b0621752983a99e027b48dac6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f6c61726176656c2d6170692d76657273696f6e696e672e737667)](https://packagist.org/packages/philiprehberger/laravel-api-versioning)[![License](https://camo.githubusercontent.com/07cf7a2c5a1ba28b1fb4e983abc6b248648e8f0fa053d00aba7bd492a7afdb8b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f6c61726176656c2d6170692d76657273696f6e696e67)](LICENSE)

Laravel middleware for API versioning with multi-source resolution from headers, Accept vendor types, and URL path segments.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

```
composer require philiprehberger/laravel-api-versioning
```

Laravel's package auto-discovery registers the service provider automatically.

Publish the config file:

```
php artisan vendor:publish --tag=api-versioning-config
```

This creates `config/api-versioning.php`.

Usage
-----

[](#usage)

### Configuration

[](#configuration)

```
// config/api-versioning.php

return [
    'supported_versions'  => ['v1', 'v2'],
    'default_version'     => 'v1',
    'latest_version'      => 'v2',
    'deprecated_versions' => [],
    'vendor_name'         => 'myapp',
    'header'              => 'X-API-Version',
    'response_headers'    => true,
];
```

### Registering the Middleware

[](#registering-the-middleware)

```
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'api.version' => \PhilipRehberger\ApiVersioning\ApiVersion::class,
    ]);
})
```

```
Route::middleware('api.version')->group(function () {
    // ...
});
```

### Accessing the Current Version

[](#accessing-the-current-version)

```
use PhilipRehberger\ApiVersioning\ApiVersion;

$version = ApiVersion::current($request); // e.g. 'v2'
```

### Version Resolution Priority

[](#version-resolution-priority)

1. `X-API-Version` request header
2. `Accept` header vendor type: `application/vnd.{vendor_name}.{version}+json`
3. URL path segment: `/api/{version}/...`
4. Configured default version

API
---

[](#api)

Method / ConceptDescription`ApiVersion::current(Request $request)`Get the resolved API version for the current request`ApiVersion` middlewareResolves version, sets request attribute, adds response headers`X-API-Version` response headerThe resolved version for each request`X-API-Deprecated` response header`true` / `false` — whether this version is deprecated### Response Headers

[](#response-headers)

HeaderValuesMeaning`X-API-Version``v1`, `v2`, ...The resolved version for this request`X-API-Deprecated``true` / `false`Whether this version is deprecated### Unsupported Version Response (400)

[](#unsupported-version-response-400)

```
{
    "error": {
        "code": "unsupported_api_version",
        "message": "API version 'v99' is not supported.",
        "supported_versions": ["v1", "v2"]
    }
}
```

Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance89

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

5

Last Release

56d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (9 commits)")

---

Tags

middlewareapilaravelrestversioning

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-laravel-api-versioning/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-laravel-api-versioning/health.svg)](https://phpackages.com/packages/philiprehberger-laravel-api-versioning)
```

###  Alternatives

[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[laragear/api-manager

Manage multiple REST servers to make requests in few lines and fluently.

161.8k](/packages/laragear-api-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
