Download the PHP package shahghasiadil/laravel-api-versioning without Composer
On this page you can find all versions of the php package shahghasiadil/laravel-api-versioning. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shahghasiadil/laravel-api-versioning
More information about shahghasiadil/laravel-api-versioning
Files in shahghasiadil/laravel-api-versioning
Package laravel-api-versioning
Short Description Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance
License MIT
Informations about the package laravel-api-versioning
Laravel API Versioning
Attribute-based API versioning for Laravel, with version detection, deprecation metadata, versioned resources, and route inspection commands.
Requirements
- PHP 8.2+
- Laravel 10, 11, 12 or 13
Installation
You can install the package via composer:
Publish the config file:
Quick Start
1. Configure supported versions
Edit config/api-versioning.php:
2. Apply middleware to API routes
api.version middleware alias is registered by the package.
3. Add version attributes to your controller
4. Call your API with a version
Features
- Controller and method level attributes (
ApiVersion,MapToApiVersion) - Version-neutral endpoints (
ApiVersionNeutral) - Deprecation metadata (
Deprecatedwith message, sunset date, replacement) - Multiple version detection methods (header, query, path, media type)
- Response headers for active/supported/deprecated versions
- Version-aware resources and resource collections
- Version inheritance and method mapping for resources
- RFC 7807 problem+json error responses for unsupported versions
- Built-in version comparison utilities
- Cache layer for attribute resolution
- Artisan commands for generation, inspection, config and health checks
- Testing base class with version request/assert helpers
Attributes
ApiVersion
Use on a controller or method.
MapToApiVersion
Use on a method to map it to specific versions.
ApiVersionNeutral
Marks controller/method as version-neutral (available in all supported versions).
Deprecated
Add deprecation metadata to controller/method.
Response Headers
When middleware is active, responses can include:
Versioned Resources
VersionedJsonResource
Extend VersionedJsonResource and implement toArrayDefault().
Then optionally add version-specific methods (toArrayV1, toArrayV11, toArrayV2, toArrayV21) or custom mappings via config.
VersionedResourceCollection
Extend VersionedResourceCollection for version-aware list payloads.
Version Comparison Helpers
In controllers/resources using HasApiVersionAttributes:
getCurrentApiVersion()isVersionDeprecated()getDeprecationMessage()getSunsetDate()getReplacedByVersion()isVersionGreaterThan()isVersionGreaterThanOrEqual()isVersionLessThan()isVersionLessThanOrEqual()isVersionBetween()
Direct service usage:
Error Format (RFC 7807)
Unsupported versions return application/problem+json:
Optional documentation is included when api-versioning.documentation.base_url is set.
Artisan Commands
Generate controller stub with attributes:
Inspect routes and versions:
Check configuration health:
Show config overview:
Clear attribute cache:
Testing Helpers
Use ShahGhasiAdil\LaravelApiVersioning\Testing\ApiVersionTestCase in package/app tests.
Available helpers include:
- Requests:
getWithVersion,getWithVersionQuery,postWithVersion,putWithVersion,deleteWithVersion - Assertions:
assertApiVersion,assertApiVersionDeprecated,assertApiVersionNotDeprecated,assertSupportedVersions,assertRouteVersions,assertDeprecationMessage,assertReplacedBy
Configuration Reference
Main file: config/api-versioning.php
Environment variables:
Development
Run tests:
Run static analysis:
Format code:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
If you discover any security-related issues, please email [email protected].
Credits
- Shahghasi Adil
- All Contributors
License
The MIT License (MIT). Please see LICENSE.md for details.
All versions of laravel-api-versioning with dependencies
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/routing Version ^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0