Getting started

Installation

Install the package, publish its configuration and declare your revision enum.

Require the package

Terminal
composer require ark4ne/laravel-api-revisions

The service provider is auto-discovered.

Publish the configuration

Terminal
php artisan vendor:publish --tag=revisions-config

This writes config/revisions.php. Every key is described in the configuration reference.

Declare the revision enum

A revision is a case of a backed enum implementing Revision. order() lists the cases oldest first, and the last one is the head.

app/Api/ApiRevision.php
use Ark4ne\ApiRevisions\Revisions\IsRevision;
use Ark4ne\ApiRevisions\Revisions\Meta;
use Ark4ne\ApiRevisions\Revisions\Revision;

enum ApiRevision: string implements Revision
{
    use IsRevision;

    #[Meta('First published revision', publishedAt: '2025-06-01')]
    case Genesis = 'genesis';

    public static function order(): array
    {
        return [self::Genesis];
    }
}

Then point the configuration at it:

config/revisions.php
'enum' => App\Api\ApiRevision::class,

Resolve the revision of each request

Put the revision middleware on your API routes. By default it reads the Api-Revision header.

routes/api.php
Route::middleware('revision')->group(function () {
    Route::get('/orders/{order}', [OrderController::class, 'show']);
});

Install the test dependency

The schema assertions of the testing helpers validate against JSON Schema:

Terminal
composer require --dev opis/json-schema

Without an enum

Until enum is set, the library works on one implicit revision, head (Revisions\Unrevisioned). Resources render, requests validate and every command succeeds, with no history. The middleware resolves nothing and adds no revision header, so clients see no difference. You can adopt the descriptors first and add revisions later.

Agent skill

The package ships an agent skill: the rules that prevent most mistakes, a reference of every entry point and tested recipes. Link it where your coding agent finds skills, for instance for Claude Code:

Terminal
mkdir -p .claude/skills
ln -s ../../vendor/ark4ne/laravel-api-revisions/skills/laravel-api-revisions \
    .claude/skills/laravel-api-revisions