Your first API client ships, then the mobile app ships, then a partner integration ships, and suddenly you can't rename a single field. Versioning is how you keep moving without breaking people.
Here's the setup I use on client Laravel APIs.
1. Version in the URL, not headers
Header-based versioning (Accept: application/vnd.app.v2+json) is elegant, but URL versioning (/api/v1/...) is easier to debug, cache, log and explain to a partner's developer. I default to the URL.
// bootstrap/app.php (Laravel 11+) ->withRouting( api: __DIR__.'/../routes/api.php', then: function () { Route::middleware('api')->prefix('api/v2') ->group(base_path('routes/api_v2.php')); }, ) 2. Version the contract, not the whole codebase
Don't copy every controller into a V2 folder. Most of the time only the response shape changes. Keep one service layer and give each version its own API Resources:
app/Http/Resources/V1/OrderResource.php app/Http/Resources/V2/OrderResource.php Controllers stay thin and shared; only the transformer differs.
3. Decide what counts as a breaking change
Write it down so the team agrees:
- Breaking: removing/renaming a field, changing a type, changing auth, changing error format, changing pagination style.
- Not breaking: adding a field, adding an endpoint, adding an optional parameter.
Non-breaking changes go into the current version. Breaking changes wait for the next one.
4. Standardise errors from day one
Changing error format later is the most painful break of all. Pick a shape (I like RFC 7807-style type/title/status/detail/errors) and render it from the exception handler for every API route.
5. Deprecate loudly
When v1 is on its way out, add headers so clients notice:
return $response ->header('Deprecation', 'true') ->header('Sunset', 'Wed, 30 Jun 2027 00:00:00 GMT'); Log which tokens still call v1 so you can email those clients directly before turning it off.
6. Test both versions in CI
A feature test per version per critical endpoint, asserting the JSON structure with assertJsonStructure. It takes an afternoon and catches accidental breaks forever.
TL;DR: URL versioning, shared services, per-version Resources, a written definition of "breaking", a consistent error format, and deprecation headers.
I'm Arun Tyagi, a freelance Laravel developer in Noida, India. I build and maintain APIs for web and mobile apps — more on my Laravel API development work at aruntyagi.com.
