PHPackages                             lukepolo/laravel-api-migrations - 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. lukepolo/laravel-api-migrations

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

lukepolo/laravel-api-migrations
===============================

Migrations for your API

0.0.5(8y ago)1011MITPHPPHP ^7.0

Since Aug 31Pushed 8y ago1 watchersCompare

[ Source](https://github.com/lukepolo/laravel-api-migrations)[ Packagist](https://packagist.org/packages/lukepolo/laravel-api-migrations)[ Docs](https://github.com/lukepolo/laravel-api-migrations)[ RSS](/packages/lukepolo-laravel-api-migrations/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (6)Versions (6)Used By (0)

Laravel API Migrations
======================

[](#laravel-api-migrations)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7a104d35b236db81f992f39daa7993dcd521960e50625047457311a969191075/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c756b65706f6c6f2f6c61726176656c2d6170692d6d6967726174696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lukepolo/laravel-api-migrations)[![Build Status](https://camo.githubusercontent.com/9fabc1363d51502d362159e8c0e1961c32655115acab0de834c8c6617021eb44/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c756b65706f6c6f2f6c61726176656c2d6170692d6d6967726174696f6e732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/lukepolo/laravel-api-migrations)[![StyleCI](https://camo.githubusercontent.com/150f98ffdb9dd72ff8ccf9839abd6bee6a226abbc73526d36d877a5f32d7292f/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130323030333539332f736869656c64)](https://styleci.io/repos/102003593)

This package is based on the [API versioning scheme used at Stripe](https://stripe.com/blog/api-versioning). Users pass a version header and you automatically migrate the request &amp; response data to match the current version of your code.

TLDR
----

[](#tldr)

You can update your API without worrying of users applications breaking with API Migrations.

You write these incrementing migrations to convert your request/responses go back in time to allow your users applications to work flawlessly.

Features
--------

[](#features)

- User Version Pinning
- Major API Versioning Supported
- Convention Supplied with artisan commands

How to use in day to day development
------------------------------------

[](#how-to-use-in-day-to-day-development)

You should create releases (including your current release) when releasing your API. This allows the system to know how to migrate a request/response to and older version of the API.

For example :

**Current** *Release V1 - 2017-08-31* expects the response :

```
    [
        'firstname' => 'Dwight',
        'lastname'  => 'Schrute',
        'title'     => 'Assistant to the Regional Manager'
    ]
```

Release *V1 - 2017-08-01* expects the response :

```
    [
        'firstname' => 'Dwight',
        'lastname'  => 'Schrute',
        'title'     => 'Assistant to the Regional Manager',
        'secret_title' => 'Assistant Regional Manager',
    ]
```

When your users are using the older API they expect to see that secret title.

It will then migrate the request **2017-08-31** to **2017-08-01**.

While this is a simple example you can see the power with these migrations to create simple steps to migrate your current version of the api to an older version of the API very easily.

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

[](#installation)

```
composer require lukepolo/laravel-api-migrations
```

### Service Provider &amp; Facade

[](#service-provider--facade)

This package supports Laravel 5.5 autoloading so the service provider and facade will be loaded automatically.

If you are using an earlier version of Laravel or have autoloading disabled you need to add the service provider and facade to `config/app.php`.

```
'providers' => [
    ...
    \LukePOLO\LaravelApiMigrations\ServiceProvider::class,
]
```

```
'aliases' => [
    ...
    'LaravelApiMigrations' => \LukePOLO\LaravelApiMigrations\Facades\LaravelApiMigrations::class,
]
```

### Middleware

[](#middleware)

Add the middleware to your Http Kernel `app/Http/Kernel.php`.

You have a couple of choices where to put this, recommenced under the api middleware!

```
protected $middlewareGroups = [
    'api' => [
        ...
        \LukePOLO\LaravelApiMigrations\LaravelApiMigrationsMiddleware::class,
    ];
]
```

### Configuration

[](#configuration)

Run the following Artisan command to publish the package configuration to `config/request-migrations.php`.

```
php artisan vendor:publish --provider="LukePOLO\LaravelApiMigrations\ServiceProvider" --tag=config
```

Usage
-----

[](#usage)

### Creating a Release

[](#creating-a-release)

You can generate a new release using the Artisan CLI.

```
php artisan make:api-release
```

### Creating a Migration

[](#creating-a-migration)

You can generate a new api migration using the Artisan CLI.

```
php artisan make:api-migration ExampleMigration
```

The command will generate a api migration and publish it to `App/Http/ApiMigrations/V{VersionNumber}/Release_{YYYY_MM_DD}/{MigrationName}`.

### Caching Migrations

[](#caching-migrations)

Once you move to prod you should cache the results

```
php artisan cache:api-migrations
```

### Making HTTP Requests

[](#making-http-requests)

By default when making a request to your API it will not run any migrations.

To use a different version of your api just attach a header :

```
    'Api-Version' : '2017-08-31'

```

### Writing the API migrations

[](#writing-the-api-migrations)

`migrateRequest` method : This is used to convert your request to be valid to your most current route

`migrateResponse` method : This is used to convert your response to what you should expect for that version

Example : -- link to gist --

### Versioning

[](#versioning)

You should use the artisan commands above to create releases, including your current release. You can also set your current versions in the config.

You can tag your current versions in your config by setting it up like this :

```
    'current_versions' => [
        'V1' => '2017-01-31',
    ],
```

``### User Version Pinning With version pinning you can automatically keep users to that API and allow them to upgrade to your latest version at their convince. Once once your user hits your api for the first time it will set the most current version.

```
php artisan vendor:publish --provider="LukePOLO\LaravelApiMigrations\ServiceProvider" --tag=migrations
```

!!!! NOTE !!!!!

You must also make the column `api_version` fillable in your `User` model!

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Credits
-------

[](#credits)

This package was original idea build by Tom Schlick, but modified heavily.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51.9% 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 ~1 days

Total

5

Last Release

3171d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/08cad1b560e2a99f9778b62506d9e82d34e6f4ec638e11d27ce7e61081130363?d=identicon)[lukepolo](/maintainers/lukepolo)

---

Top Contributors

[![lukepolo](https://avatars.githubusercontent.com/u/2066668?v=4)](https://github.com/lukepolo "lukepolo (82 commits)")[![tomschlick](https://avatars.githubusercontent.com/u/70184?v=4)](https://github.com/tomschlick "tomschlick (58 commits)")[![sixlive](https://avatars.githubusercontent.com/u/5108034?v=4)](https://github.com/sixlive "sixlive (14 commits)")[![jbrooksuk](https://avatars.githubusercontent.com/u/246103?v=4)](https://github.com/jbrooksuk "jbrooksuk (4 commits)")

---

Tags

httpmiddlewarelaravelmigrationsrequestsrequest-migrationsapi-migrations

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lukepolo-laravel-api-migrations/health.svg)

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

###  Alternatives

[tomschlick/request-migrations

HTTP Request Migrations

1844.5k](/packages/tomschlick-request-migrations)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[matthewbdaly/laravel-etag-middleware

A Laravel middleware for adding ETags to HTTP requests to improve response times

64326.0k2](/packages/matthewbdaly-laravel-etag-middleware)

PHPackages © 2026

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