sowl/laravel-doctrine-jsonapi

Package for the Laravel that allows developers to create JSON:API endpoints using the Doctrine ORM for data persistence.

10.0.5 2025-04-01 11:35 UTC

README

Implement feature-rich JSON:API compliant APIs in your Laravel applications using Doctrine ORM.

Overview

This package provides a comprehensive implementation of the JSON:API specification for Laravel applications using Doctrine ORM instead of Eloquent. It reduces boilerplate code by offering default controllers and actions that handle standard API operations while ensuring full compliance with the JSON:API standard.

Features

  • Complete JSON:API Implementation: Full compliance with the JSON:API specification
  • Built for Doctrine ORM: Designed specifically for Laravel applications using Doctrine ORM
  • Battle-tested: Production-ready and robust
  • Standardised, Consistent APIs: Uniform interface for all resources
  • Resource Operations:
    • Fetch resources with advanced querying
    • Fetch and manipulate relationships
    • Inclusion of related resources (compound documents)
    • Sparse field sets
    • Sorting
    • Pagination
    • Filtering
  • Full CRUD Support:
    • Create resources
    • Update resources
    • Update relationships
    • Delete resources
  • Authorization: Policy-based access control

Quick Start

Installation

composer require sowl/laravel-doctrine-jsonapi

Configuration

php artisan vendor:publish --provider="Sowl\JsonApi\JsonApiServiceProvider"

Usage

  1. Implement ResourceInterface on your Doctrine entities
  2. Create transformers extending AbstractTransformer
  3. Define entity relationships using RelationshipsCollection
  4. Register resources in the config/jsonapi.php file
  5. Use the default controller or create custom ones

Documentation

For detailed installation instructions, configuration guides and tutorials:

Read the Documentation

Development

Clone the project locally.

Install the package dependencies and run the tests:

docker compose run php

To enter the docker container:

docker compose run php sh

Testing

Testing Documentation

Roadmap

  • Add documentation about the meta param usage. ( meta[account]=mailbox&meta[profile]=completeness )
  • Make it possible to disable links generation. As it is not required by JSON:API spec and increases response size.
  • Create a validation rule "resource", "resourceExists" for validating resource identifier. Example of usage: php $this->validate($request, [ 'data' => 'required|resource:users', ]);
  • Create default global error handler or write down documentation how to create such one. How to handle missing route\endpoint 404 and internal 500 errors.
  • Create console command for resource policy generation: "jsonapi:make:policy".
  • Checkout option for adding include params like "include=roles:sort" (TransformerAbstract.php:173)