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

ActiveLibrary[API Development](/categories/api)

galviadigital/json-api
======================

A Lightweight JSON:API Resource for Laravel

1.0.0(2y ago)087MITPHPPHP ^8.1 || ^8.2

Since Aug 10Pushed 2y agoCompare

[ Source](https://github.com/JordanGalviaDigital/json-api)[ Packagist](https://packagist.org/packages/galviadigital/json-api)[ RSS](/packages/galviadigital-json-api/feed)WikiDiscussions main Synced yesterday

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

[![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. Modified version of [Timacdonald/json=api](https://github.com/timacdonald/json-api) to fix some outstanding pull requests that are not yet merged into main.

> **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**

- [Version support](#version-support)
- [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)

Version support
---------------

[](#version-support)

- **PHP**: `8.1`, `8.2`
- **Laravel**: `^8.73.2`, `^9.0`, `10.x-dev`

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.

```
