PHPackages                             garbetjie/laravel-jsonapi - 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. garbetjie/laravel-jsonapi

AbandonedArchivedLibrary[API Development](/categories/api)

garbetjie/laravel-jsonapi
=========================

Easily generate JSON:API response structures using Laravel's Resources.

0.8.3(5y ago)1875MITPHPPHP ^7.3 || ^7.4 || ^8.0

Since Mar 17Pushed 5y agoCompare

[ Source](https://github.com/garbetjie/laravel-jsonapi)[ Packagist](https://packagist.org/packages/garbetjie/laravel-jsonapi)[ RSS](/packages/garbetjie-laravel-jsonapi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (15)Used By (0)

Laravel JSON:API
================

[](#laravel-jsonapi)

Yet another Laravel package that helps you get up and running with JSON:API.

The idea behind this package is to make it as easy as possible to easily get up &amp; running with JSON:API whilst making use of [Laravel's Resource](https://laravel.com/docs/7.x/eloquent-resources).

[![Build status](https://camo.githubusercontent.com/049c02b82d8c85e60b7583a0bf6a0e7430df509d5024bd5585a0afda1c2df4aa/68747470733a2f2f6170692e7472617669732d63692e6f72672f6761726265746a69652f6c61726176656c2d6a736f6e6170692e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/049c02b82d8c85e60b7583a0bf6a0e7430df509d5024bd5585a0afda1c2df4aa/68747470733a2f2f6170692e7472617669732d63692e6f72672f6761726265746a69652f6c61726176656c2d6a736f6e6170692e7376673f6272616e63683d6d6173746572) [![PHP from Packagist](https://camo.githubusercontent.com/a69218169cca2b11dd4b10c845761b7eb9d98d43e0d1abfeb4e263c2603dd3a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6761726265746a69652f6c61726176656c2d6a736f6e617069)](https://camo.githubusercontent.com/a69218169cca2b11dd4b10c845761b7eb9d98d43e0d1abfeb4e263c2603dd3a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6761726265746a69652f6c61726176656c2d6a736f6e617069)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
    - [Using `JsonApiResourceInterface`](#using-jsonapiresourceinterface)
    - [Using `ConvertibleToJsonApiResourceInterface`](#using-convertibletojsonapiresourceinterface)
    - [Collections of resources](#using-collections)
- Loading includes. *(Still to be documented)*
- Extracting resources for including. *(Still to be documented)*
- Pagination and filters. *(Still to be documented)*
- [Changelog](#changelog)

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

[](#installation)

```
composer require garbetjie/laravel-jsonapi

```

Basic Usage
-----------

[](#basic-usage)

In order to generate JSON:API resources with this package, simply return an instance of `Garbetjie\Laravel\JsonApi\JsonApiResource`from your controller method.

This can be done through creating your own resources that extend `JsonApiResource`, or through creating a new instance of `JsonApiResource` directly, and passing in a value that can be converted to a resource (see the following sections on how to do this).

### Using `JsonApiResourceInterface`

[](#using-jsonapiresourceinterface)

When implementing `Garbetjie\Laravel\JsonApi\JsonApiResourceInterface`, the object that is implementing the interface is directly responsible for representing itself as a JSON:API resource. This means that *any* object can be used to represent a JSON:API resource.

The easiest way of doing this is ensuring that an instance of an [Eloquent Resource](https://laravel.com/docs/7.x/eloquent-resources)implements this interface, as there are a number of helper methods available that make it easier to work with Eloquent models.

#### Resource definition

[](#resource-definition)

```
