PHPackages                             m-hidayatullahh/laravel-api-kit - 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. [API Development](/categories/api)
4. /
5. m-hidayatullahh/laravel-api-kit

ActiveLibrary[API Development](/categories/api)

m-hidayatullahh/laravel-api-kit
===============================

Standardized API response envelope and global exception handling for Laravel 10 &amp; 11.

v1.0.0(1mo ago)011↓90%MITPHPPHP ^8.1

Since Jun 3Pushed 1mo agoCompare

[ Source](https://github.com/m-hidayatullahh/laravel-api-kit)[ Packagist](https://packagist.org/packages/m-hidayatullahh/laravel-api-kit)[ RSS](/packages/m-hidayatullahh-laravel-api-kit/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

company/laravel-api-kit
=======================

[](#companylaravel-api-kit)

Standardized API response envelope + global exception handling for **Laravel 10 &amp; 11**, PHP 8.1+.

One install gives every backend project the same success/error/validation/pagination shape, so the frontend writes one set of handlers instead of many.

Install
-------

[](#install)

Private repo via `composer.json`:

```
{
  "repositories": [
    { "type": "vcs", "url": "git@github.com:company/laravel-api-kit.git" }
  ]
}
```

```
composer require company/laravel-api-kit
php artisan vendor:publish --tag=api-kit-config   # optional
php artisan vendor:publish --tag=api-kit-lang     # optional
```

The ServiceProvider and `ApiResponse` facade auto-register (package discovery).

Response shapes
---------------

[](#response-shapes)

Success:

```
{ "success": true, "message": "Data berhasil diambil", "data": {} }
```

Validation error (422):

```
{ "success": false, "message": "Validation failed", "errors": { "email": ["Email wajib diisi"] } }
```

Server error (500): `{ "success": false, "message": "Terjadi kesalahan pada server" }`Unauthorized (401): `{ "success": false, "message": "Unauthorized" }`Not found (404): `{ "success": false, "message": "Data tidak ditemukan" }`

Usage
-----

[](#usage)

```
use Company\ApiKit\Facades\ApiResponse;

return ApiResponse::success($user, 'Data berhasil diambil');
return ApiResponse::error('Gagal memproses', 400);
return ApiResponse::validation(['email' => ['Email wajib diisi']]);
return ApiResponse::unauthorized();
return ApiResponse::forbidden();
return ApiResponse::notFound();
return ApiResponse::paginate(User::paginate());
```

Or via the controller trait:

```
use Company\ApiKit\Traits\HasApiResponse;

class UserController extends Controller
{
    use HasApiResponse;

    public function index()
    {
        return $this->respondPaginated(User::paginate());
    }
}
```

Throwing for business rules (no try/catch needed — the renderer formats it):

```
use Company\ApiKit\Exceptions\BusinessException;

throw new BusinessException('Saldo tidak mencukupi', status: 422);
```

Wiring global exception handling
--------------------------------

[](#wiring-global-exception-handling)

### Laravel 11 — bootstrap/app.php

[](#laravel-11--bootstrapappphp)

```
use Company\ApiKit\ApiKit;

->withExceptions(function (Illuminate\Foundation\Configuration\Exceptions $exceptions) {
    ApiKit::handleExceptions($exceptions);
})
```

### Laravel 10 — app/Exceptions/Handler.php

[](#laravel-10--appexceptionshandlerphp)

```
use Company\ApiKit\Exceptions\Concerns\InteractsWithApiExceptions;

class Handler extends ExceptionHandler
{
    use InteractsWithApiExceptions;

    public function register(): void
    {
        $this->renderApiExceptions();
    }
}
```

Configuration highlights
------------------------

[](#configuration-highlights)

- `api_prefix` — which routes get standardized JSON errors (default `api`).
- `include_code` — add a machine-readable `code` (e.g. `VALIDATION_FAILED`) to error bodies.
- `keys` — rename envelope keys for incremental legacy migration.
- `logging` — 5xx are logged by default; 4xx are not.
- Messages live in publishable lang files (`id`, `en`). Set `app.locale` or edit after publish.

Testing
-------

[](#testing)

```
composer install
composer test
```

Built with Pest + Orchestra Testbench.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

51d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/184669567?v=4)[M.Hidayatullah](/maintainers/m-hidayatullahh)[@m-hidayatullahh](https://github.com/m-hidayatullahh)

---

Top Contributors

[![m-hidayatullahh](https://avatars.githubusercontent.com/u/184669567?v=4)](https://github.com/m-hidayatullahh "m-hidayatullahh (2 commits)")

---

Tags

laravel-apilaravel-api-kitlaravel-kitlaravel-packageresponseapilaravelexceptionstandardization

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/m-hidayatullahh-laravel-api-kit/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

813336.8k3](/packages/defstudio-telegraph)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77922.3M186](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.6k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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