2017 © Pedro Peláez
 

library illuminate-json-guard

Laravel/Lumen integration for league/json-guard

image

yuloh/illuminate-json-guard

Laravel/Lumen integration for league/json-guard

  • Wednesday, January 4, 2017
  • by yuloh
  • Repository
  • 1 Watchers
  • 1 Stars
  • 545 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

Json Schema Validation For Laravel And Lumen

Laravel/Lumen integration for league/json-guard., (*1)

This package is experimental and could break at any time., (*2)

Install

Via Composer, (*3)

``` bash $ composer require yuloh/illuminate-json-guard, (*4)


### Register The Service Provider Add the following line to `app/boostrap.php`: ```php $app->register(Yuloh\JsonGuard\Illuminate\LumenServiceProvider::class);

Publish The Config File

As Lumen does not ship with a publish command, you will have to copy the config file manually., (*5)

cp ./vendor/league/illuminate-json-guard/config/json-guard.php ./config/json-guard.php

Usage

Controller Validation

You can use the provided ValidatesJsonRequests trait to easily validate requests against a JSON Schema., (*6)

The trait provides a validateJson method. Simply call the method with the current request and the name of the schema you would like to use, and the request body will be validated against the schema., (*7)

if validation fails, the method will throw a JsonSchemaValidationException. The exception will be converted into a JSON response will all of the relevant error messages., (*8)

``` php use Yuloh\JsonGuard\Illuminate\Http\ValidatesJsonRequests;, (*9)

class UsersController extends Controller { use ValidatesJsonRequests;, (*10)

public function show(Request $request, int $id)
{
    $this->validateJson($request, 'user.json');

    return User::find($id);
}

}, (*11)


### Route Middleware A route middleware is also included. The route middleware takes the name of the schema you would like to use the as the only parameter. If validation fails the middleware will return a JSON response of the errors instead of passing through to your handler. ```php $app->post('/users', ['middleware' => 'json-schema:user.json', function () { // }]);

Loading Schemas

@todo, (*12)

Localization

@todo, (*13)

Customizing The Error Response

@todo, (*14)

Testing

bash $ composer test, (*15)

License

The MIT License (MIT). Please see License File for more information., (*16)

The Versions

23/12 2016

dev-neomerx-response-support

dev-neomerx-response-support https://github.com/thephpleague/illuminate-json-guard

Laravel/Lumen integration for league/json-guard

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel lumen illuminate json schema json-guard