PHPackages                             tpjasar/laravel-api-foundation - 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. tpjasar/laravel-api-foundation

ActiveLibrary

tpjasar/laravel-api-foundation
==============================

API versioning, standard JSON response/error format, and pagination for Laravel APIs

10PHP

Since Mar 10Pushed 1w agoCompare

[ Source](https://github.com/tpjasar/laravel-api-foundation)[ Packagist](https://packagist.org/packages/tpjasar/laravel-api-foundation)[ RSS](/packages/tpjasar-laravel-api-foundation/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel API Foundation
======================

[](#laravel-api-foundation)

Keeps your Laravel API consistent: versioned routes (v1, v2, v3…), same JSON shape for success and errors, and pagination. No config needed for new versions - just use them in the URL.

Install
-------

[](#install)

```
composer require tpjasar/laravel-api-foundation
```

Publish config (optional):

```
php artisan vendor:publish --tag=api-foundation-config
```

Versioned routes
----------------

[](#versioned-routes)

Hit `/api/v1/users`, `/api/v2/users`, `/api/v99/users`- all work. No need to add each version in config.

In `App\Providers\RouteServiceProvider` or `routes/api.php`:

```
use Tpjasar\ApiFoundation\Route\VersionedRoute;

VersionedRoute::register(function () {
    Route::get('users', [UserController::class, 'index']);
    Route::get('users/{id}', [UserController::class, 'show']);
});
```

This registers `/api/v1/users`, `/api/v2/users`, `/api/v3/users`, etc. Get the current version in your handler: `request()->route('version')`.

Response format
---------------

[](#response-format)

Success responses:

```
use Tpjasar\ApiFoundation\Response\ApiResponse;

return ApiResponse::success($user, 'User found');
// { "data": {...}, "message": "User found" }

return ApiResponse::success($users);
// { "data": [...] }
```

Error format
------------

[](#error-format)

```
return ApiResponse::error('Not found', 404, null, 404);
// { "error": { "code": 404, "message": "Not found" } }

return ApiResponse::error('Validation failed', 422, $validator->errors(), 422);
// { "error": { "code": 422, "message": "Validation failed", "details": {...} } }
```

Pagination
----------

[](#pagination)

```
$users = User::paginate(15);
return ApiResponse::paginated($users);
// { "data": [...], "meta": { "current_page": 1, "per_page": 15, "total": 50, "last_page": 4 } }
```

Config
------

[](#config)

Publish with `--tag=api-foundation-config`. You can change the JSON keys (data\_key, error\_key, etc.) and pagination meta keys. Set `prefix` to `''` if your routes are already under `api`.

License
-------

[](#license)

MIT

Author
------

[](#author)

Muhammad Jasar T P

###  Health Score

21

—

LowBetter than 21% of packages

Maintenance64

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/15633479d5d10f1aa1a43bfcdb6fb15e3bb5e5aa95e614ec7608f9c017bd90ed?d=identicon)[tpjasar](/maintainers/tpjasar)

---

Top Contributors

[![tpjasar](https://avatars.githubusercontent.com/u/24247323?v=4)](https://github.com/tpjasar "tpjasar (3 commits)")

### Embed Badge

![Health badge](/badges/tpjasar-laravel-api-foundation/health.svg)

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

PHPackages © 2026

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