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

ActiveLibrary[API Development](/categories/api)

timacdonald/json-api
====================

A Lightweight JSON:API Resource for Laravel

v0.2.1(4y ago)639892.5k—3.2%49[8 issues](https://github.com/timacdonald/json-api/issues)[3 PRs](https://github.com/timacdonald/json-api/pulls)2MITPHPPHP ^7.4 || ^8.0CI passing

Since Nov 21Pushed 1mo ago7 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (21)Used By (2)

[![JSON:API Resource: a Laravel package by Tim MacDonald](https://raw.githubusercontent.com/timacdonald/json-api/main/art/header.png)](https://raw.githubusercontent.com/timacdonald/json-api/main/art/header.png)

`JSON:API` Resource for Laravel
===============================

[](#jsonapi-resource-for-laravel)

A lightweight API resource for Laravel that helps you adhere to the `JSON:API` standard with support for sparse fieldsets, compound documents, and more baked in.

> **Note** These docs are not designed to introduce you to the `JSON:API` specification and the associated concepts, instead you should [head over and read the specification](https://jsonapi.org) if you are not yet familiar with it. The documentation that follows only covers *how* to implement the specification via the package.

**Table of contents**

- [Installation](#installation)
- [Getting started](#getting-started)
    - [Creating your first `JSON:API` resource](#creating-your-first-jsonapi-resource)
    - [Adding attributes](#adding-attributes)
    - [Adding relationships](#adding-relationships)
- [A note on eager loading](#a-note-on-eager-loading)
- [Digging deeper](#digging-deeper)
    - [Attributes](#attributes)
        - [`toAttributes()`](#toAttributes)
        - [Sparse fieldsets](#sparse-fieldsets)
        - [Minimal attributes](#minimal-attributes)
        - [Lazy attribute evaluation](#lazy-attribute-evaluation)
    - [Relationships](#relationships)
        - [`toRelationships()`](#toRelationships)
        - [Customising the relationship resource class guessing](#customising-the-relationship-resource-class-guessing)

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

[](#installation)

You can install using [composer](https://getcomposer.org/) from [Packagist](https://packagist.org/packages/timacdonald/json-api).

```
composer require timacdonald/json-api
```

Getting started
---------------

[](#getting-started)

The `JsonApiResource` class provided by this package is a specialisation of Laravel's [Eloquent API resource](https://laravel.com/docs/eloquent-resources). All public facing APIs are still accessible; in a controller, for example, you interact with a `JsonApiResource` as you would with Laravel's `JsonResource` class.

```
