PHPackages                             z1lab/laravel-json-api - 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. z1lab/laravel-json-api

ActiveLibrary[API Development](/categories/api)

z1lab/laravel-json-api
======================

A minimal library for normalize Laravel app to return Json Api results.

v0.1.0(7y ago)0112MITPHPPHP &gt;=7.1.3

Since Nov 3Pushed 7y agoCompare

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

READMEChangelog (1)Dependencies (11)Versions (11)Used By (0)

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

[](#installation)

```
composer require z1lab/laravel-json-api

```

Define .env keys:

`CACHE_LIFETIME` for set the default cache lifetime.

`PAGINATION_SIZE` for define the page size of collection results (Ex: GET index method).

PS: This package manipulate the cache using Cache::tags() so change the the `CACHE_DRIVER` to `redis` or `memcache` and install the required dephs. By default the `predis/predis` is included on the composer.json.

Introduction
------------

[](#introduction)

Laravel Json Api is a minimal library for normalize Laravel Apps to return Json Api results.

Before start take a look in the [Json API Spec](https://jsonapi.org/).

This package takes advantage of [Laravel Eloquent Api Resources](https://laravel.com/docs/5.7/eloquent-resources) and some simple dependencies for improve the Json API pattern:

[API Version Control](https://github.com/juampi92/api-resources)

[API Exception Handler](https://github.com/esbenp/heimdal)

[CORS Middleware](https://github.com/barryvdh/laravel-cors)

[HTTP Cache](https://github.com/barryvdh/laravel-httpcache)

After starts, check the packages official docs for the default configuration of each one.

Usage
-----

[](#usage)

Just extends the required classes and apply the error handling.

### Error handling

[](#error-handling)

Change the render() method in the App\\Exceptions\\Handler:

```
use Z1lab\JsonApi\Exceptions\ApiHandler;

public function render($request, Exception $exception)
    {
        if($request->wantsJson()) {
            $handler = new ApiHandler($this->container);

            return $handler->render($request, $exception);
        }

        return parent::render($request, $exception);
    }
```

### API Controllers

[](#api-controllers)

In your controller class just extends the ApiController and set the constructor according the following example:

```
use Z1lab\JsonApi\Http\Controllers\ApiController;

class AwesomeController extends ApiController
{
    public function __construct(AwesomeRepository $repository)
    {
        parent::__construct($repository, 'Awesome');
    }
}
```

The fist parameter sets the repository for access the datasets; The second parameter defines the namespace to JsonResource class.

The ApiController extends all base methods from Laravel BaseController and delivery the initial methods for your ApiResourceController:

`public function index() {}`

`public function show(string $id) {}`

`public function destroy(string $id) {}`

`public function makeResource($obj) {}`

`public function collectResource($collection) {}`

You only have to implement the `store()` and `update()` methods with your FormRequest rules.

### Api FormRequests

[](#api-formrequests)

For optimal handle errors in yours FormRequests Just extends the ApiFormRequest class:

```
use Z1lab\JsonApi\Http\Requests\ApiFormRequest;

class AwesomeFormRequest extends ApiFormRequest {}
```

### Api Repositories

[](#api-repositories)

In your repository class just extends the ApiRepository and set the constructor according the following example:

```
use Z1lab\JsonApi\Repositories\ApiRepository;

class AwesomeRepository extends ApiRepository
{
    public function __construct(Awesome $model)
    {
        parent::__construct($model, 'awesome');
    }
}
```

The fist parameter sets the model for access the data; The second parameter defines the cache prefix name.

The ApiRepository delivery some common methods for you handle your data accross the app.

`public function create(array $data) {}`

`public function update(array $data, string $id) {}`

`public function destroy(string $id) {}`

`public function find(string $id, array $with = []) {}`

`public function list(int $items = 0) {}`

`public function findWhere(string $column, $value, array $with = []) {}`

`public function all(array $keys = []) {}`

License
-------

[](#license)

Laravel Json Api is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Every ~19 days

Recently: every ~35 days

Total

9

Last Release

2591d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0b43cb681daed29217ea5ff945e0c211b74012050045002d365c848f8fd4b3b?d=identicon)[webmaster-z1lab](/maintainers/webmaster-z1lab)

---

Top Contributors

[![olimarferraz](https://avatars.githubusercontent.com/u/6013739?v=4)](https://github.com/olimarferraz "olimarferraz (10 commits)")

---

Tags

jsonapilaravelresource

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/z1lab-laravel-json-api/health.svg)

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

###  Alternatives

[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

71510.9M66](/packages/laravel-mcp)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[galahad/laravel-addressing

Laravel package providing addressing functionality

70316.6k](/packages/galahad-laravel-addressing)[dragon-code/laravel-json-response

Automatically always return a response in JSON format

1118.6k1](/packages/dragon-code-laravel-json-response)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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