Skip to content
Laravel Packagev13.xMIT License0+ downloadsAI Ready · Laravel Boost

API Versioning: Version your API with Laravel's own routes

API Versioning adds versions to the routes you already write with Route. Read the version from a header, the query string or the path, serve a different controller per version from one cacheable route, and shape JSON resources per version, without a custom router, base class or forced URL. It is AI ready: php artisan boost:install teaches your coding agent the whole package through Laravel Boost.

$composer require pharaonic/laravel-api-versioning

Compatibility

Each line is released for the versions in its row, read from that release's composer.json. Pick the line that matches your project; a combination not listed isn't supported. Find the right line of every package for your project.

LineLatest releasePHPLaravelStatusDocs
v13.xv13.0.2 Nov 23, 20268.3 – 8.513Current Docs: Read the v13.x docs
v12.xv12.0.2 Nov 23, 20268.2 – 8.512Maintained Docs: Read the v12.x docs
v11.xv11.0.2 Nov 23, 20268.2 – 8.411MaintainedLaravel 11 no longer gets security fixes Docs: Read the v11.x docs
v10.xv10.0.2 Nov 23, 20268.1 – 8.310MaintainedLaravel 10 no longer gets security fixes Docs: Read the v10.x docs
v9.xv9.0.0 Nov 23, 20268.0 – 8.29MaintainedLaravel 9 no longer gets security fixes Docs: Read the v9.x docs
v8.xv8.0.0 Nov 23, 20268.0 – 8.18MaintainedLaravel 8 no longer gets security fixes Docs: Read the v8.x docs
v7.xv7.0.0 Nov 23, 20268.07MaintainedLaravel 7 no longer gets security fixes Docs: Read the v7.x docs
v6.xv6.0.0 Nov 23, 20268.06MaintainedLaravel 6 no longer gets security fixes Docs: Read the v6.x docs

Maintenance

Latest release
v13.0.2
Nov 23, 2026 (16 hours ago)
Released lines
8
documented lines with a release; see compatibility
CI on develop
Tests passed
latest run Nov 23, 2026

From the package's releases and its GitHub Actions. A passing run means the test suite passed on develop, on every PHP version it supports; it isn't a security review, and each release line has its own runs on GitHub. Checked hourly.

A quick look

One route per URI, a controller per version, and a v2-only endpoint.

routes/api.php
1use App\Http\Controllers\ReportController;
2use App\Http\Controllers\UserController;
3use App\Http\Controllers\UserV1Controller;
4use App\Http\Controllers\UserV2Controller;
5 
6Route::get('users/{user}', [UserController::class, 'show'])->controllers([
7 'v1' => [UserV1Controller::class, 'show'],
8 'v2' => [UserV2Controller::class, 'show'],
9]);
10 
11Route::sinceVersion('v2')->middleware('auth:api')->group(function () {
12 Route::apiResource('reports', ReportController::class);
13});
14 
15// GET /api/users/1 X-API-Version: v2 → UserV2Controller@show
Key Features

Everything an evolving API needs

Add a version list to the config and a constraint to your routes.

Native Route API

Route::version('v2')->middleware(...)->group(...) and ->sinceVersion('v2') on any route, resource or group.

Header, Query or Path

Resolve X-API-Version, ?version=, an api/{version} prefix or your own resolver; conflicts are rejected.

Controller per Version

One route per URI runs UserV2Controller for v2, with its middleware, bindings and policies.

Versioned Resources

whenVersion('>=v2', ...) removes fields entirely and never runs the closures of removed fields.

Deprecation and Sunset

RFC 9745 Deprecation, RFC 8594 Sunset and Link headers per version, and retired versions return 410.

Cache and Octane Safe

Works with route:cache and config:cache, and keeps the version on the request only.

Predictable Errors

ApiVersionException carries an error code per case and configurable status codes, and never repeats the version the client sent.

Checked at Registration

Unknown versions, invalid controller maps and duplicate routes or names fail when routes load, not on a request.

AI Ready

Ships a Laravel Boost guideline and an api-versioning-development skill, so php artisan boost:install teaches Claude Code, Cursor, Codex or Copilot the whole API.

FAQ

API Versioning Questions

Quick answers about installing and using API Versioning.

What is API Versioning?

Laravel-native API versioning. Version groups and constraints on Route, header, query and path resolution, a controller per version on one cacheable route, and versioned JSON resources. It's a free, open-source Laravel package by Pharaonic.

How do I install API Versioning?

Run composer require pharaonic/laravel-api-versioning in your project's root directory.

What does API Versioning require?

The latest release requires PHP 8.3 – 8.5 and Laravel 13.

Does it add /api/v1 to my URLs?

No. Versions are route metadata. A URL prefix is only added when you configure a path template such as api/{version}, or write the prefix yourself.

Does it work with route:cache?

Yes. Version constraints and controller maps are plain strings in the route action, and the package is tested by caching routes and serving requests from a freshly booted application.

What happens when a version has no controller?

The request is not found (404 by default). The package never falls back to another version's controller unless the route explicitly falls back to its own.

Is API Versioning free to use?

Yes. API Versioning is open source under the MIT license, so you can use it in personal and commercial projects.

Where can I find the API Versioning documentation?

Read the API Versioning documentation for setup, configuration, and usage examples.

How do I report a bug or contribute to API Versioning?

Open an issue or a pull request on GitHub, ask in GitHub Discussions, or chat with us on Discord.

Ready to dig in?

Read the full documentation for version groups, route constraints, header, query and path resolution, version controllers, versioned resources, lifecycle headers and route caching.