sowl / laravel-doctrine-jsonapi
Package for the Laravel that allows developers to create JSON:API endpoints using the Doctrine ORM for data persistence.
Requires
- php: ^8.1
- doctrine/orm: ^2.14
- laravel/framework: ^10.0
- league/fractal: ^0.20.1
- ramsey/uuid: ^4.7
Requires (Dev)
- doctrine/annotations: ^2
- fakerphp/faker: ^1.24
- gedmo/doctrine-extensions: ^3.11
- laravel-doctrine/extensions: ^1.6
- laravel-doctrine/migrations: ^3.1
- laravel-doctrine/orm: ^2.0
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-04-01 18:22:32 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
- Implement
ResourceInterface
on your Doctrine entities - Create transformers extending
AbstractTransformer
- Define entity relationships using
RelationshipsCollection
- Register resources in the
config/jsonapi.php
file - Use the default controller or create custom ones
Documentation
For detailed installation instructions, configuration guides and tutorials:
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
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)