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

ActiveLibrary[API Development](/categories/api)

gravure/laravel-json-api
========================

Native integration of the Json API specification.

1.5(7y ago)34402[2 issues](https://github.com/gravure/laravel-json-api/issues)MITPHPPHP &gt;=7.1.0

Since Oct 25Pushed 7y ago4 watchersCompare

[ Source](https://github.com/gravure/laravel-json-api)[ Packagist](https://packagist.org/packages/gravure/laravel-json-api)[ RSS](/packages/gravure-laravel-json-api/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

Laravel JSON api
================

[](#laravel-json-api)

[![codecov](https://camo.githubusercontent.com/b922afcd9cf1dd3248eb676cdde6f96540d7a93da2e3d9ff3196fdd9cd088271/68747470733a2f2f636f6465636f762e696f2f67682f677261767572652f6c61726176656c2d6a736f6e2d6170692f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/gravure/laravel-json-api)

This package assists at generating [JSON API v1](http://jsonapi.org/) compatible output.

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

[](#installation)

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

Register the service provider in your `config/app.php` under `providers`:

```
    Gravure\Api\Providers\ApiProvider::class,
```

Usage
-----

[](#usage)

An important element of this package is the `ReplacesRequest` middleware that is automatically active for any request that accepts `application/vnd.api+json` content. The inject Request object provides a set of helper subclasses, for instance for handling pagination or filtering.

Aside from that, by extending the abstract ResourceController or Controller one can easily generate Json documents based on the specification. The ResourceController in fact provides a complete Laravel ResourceController implementation, where it only needs a Repository to process database specific logic.

Example
-------

[](#example)

This is a simple example with a `Post` having one or more `Comment` and a single author `User`.

```
