PHPackages                             drpdigital/laravel-json-api-parser - 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. drpdigital/laravel-json-api-parser

ActiveLibrary[API Development](/categories/api)

drpdigital/laravel-json-api-parser
==================================

Laravel integration for the jsonapi.org parser

0.0.5(6y ago)31.8k2[1 issues](https://github.com/drpdigital/laravel-json-api-parser/issues)MITPHP

Since Jan 7Pushed 6y ago3 watchersCompare

[ Source](https://github.com/drpdigital/laravel-json-api-parser)[ Packagist](https://packagist.org/packages/drpdigital/laravel-json-api-parser)[ RSS](/packages/drpdigital-laravel-json-api-parser/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (6)Versions (6)Used By (0)

JSON API parser for Laravel
===========================

[](#json-api-parser-for-laravel)

[![Build Status](https://camo.githubusercontent.com/74f5294d4325152eb1c10f3be5821ab2e71591336efd41cd4311fdd87a7f41d5/68747470733a2f2f7472617669732d63692e6f72672f6472706469676974616c2f6c61726176656c2d6a736f6e2d6170692d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/drpdigital/laravel-json-api-parser)[![Coverage Status](https://camo.githubusercontent.com/ec6fa1e87594ede9b78f6c7f0efe978f8aefe5ec7d352cd1b735dafdf49ec78e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6472706469676974616c2f6c61726176656c2d6a736f6e2d6170692d7061727365722f62616467652e737667)](https://coveralls.io/github/drpdigital/laravel-json-api-parser)[![GitHub Releases](https://camo.githubusercontent.com/2bbe1d60128e9a24ecbf7590a199ac863e274a44ddb94d9321b727212b8b40fe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6472706469676974616c2f6c61726176656c2d6a736f6e2d6170692d7061727365722e737667)](https://github.com/drpdigital/laravel-json-api-parser)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/drpdigital/laravel-json-api-parser/blob/master/LICENSE)

This is a Laravel framework integration for the [JSON API parser](https://github.com/drpdigital/json-api-parser).

The JSON API parser allows you to read and validate requests that are structured with the [jsonapi.org](https://jsonapi.org) specification.

Version compatibility
---------------------

[](#version-compatibility)

JSON API Parser versionLaravel VersionPHP Version1.X5.1 - 5.6&gt;= 5.6Installation
------------

[](#installation)

You install the package by using composer:

```
composer require drpdigital/laravel-json-api-parser
```

If you are using `Laravel 5.5` onwards the package will automatically register itself.

If you are on `Laravel 5.4` or lower then you will need to register the service provider in your `config/app.php`

```
'providers' => [
    ...
    \Drp\LaravelJsonApiParser\JsonApiParserServiceProvider::class,
    ...
]
```

Documentation
-------------

[](#documentation)

### How to validate your resources

[](#how-to-validate-your-resources)

When wanting to validate a resource within your payload, you need to give the `JsonApiValidator` a `ValidatorExecutor`. This can be done in a few ways specified below. With all of these the first parameter is a string of the type of resource it needs to validate.

So for example if you had a request like:

```
{
  "data": {
    "id": 1,
    "type": "user",
    "attributes": {
      "name": "Bob"
    }
  }
}
```

Then your first parameter would be `'user'`.

#### Using `::make`

[](#using-make)

```
$jsonApiValidator = app(JsonApiValidator::class);
$jsonApiValidator->validator(
    'user',
    \Drp\LaravelJsonApiParser\Validation\Validator::make(
        ['name' => 'required'],
        ['name.required' => 'You must provide a name']
    )
);
```

The rules and messages you provide are whatever Laravel can support as our validator is just a decorated for Laravel's.

#### Using custom class

[](#using-custom-class)

When using a custom validator class you will need to extend our validator class `\Drp\LaravelJsonApiParser\Validation\Validator`. You then specify a `rules` and `messages` function inside the class and return an array of rules and messages in their respective functions.

```
