https://github.com/webtoolsnz/laravel-json-schema-request
Laravel's Form Request Validation, but for json-schema documents
https://github.com/webtoolsnz/laravel-json-schema-request
form-request-validation json-schema json-schema-validator laravel
Last synced: 2 months ago
JSON representation
Laravel's Form Request Validation, but for json-schema documents
- Host: GitHub
- URL: https://github.com/webtoolsnz/laravel-json-schema-request
- Owner: webtoolsnz
- License: mit
- Created: 2020-06-18T09:35:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T22:57:16.000Z (almost 6 years ago)
- Last Synced: 2025-09-25T09:36:35.107Z (8 months ago)
- Topics: form-request-validation, json-schema, json-schema-validator, laravel
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 25
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
JSON Schema Request
================================
[](https://github.com/webtoolsnz/laravel-json-schema-request/workflows/continuous-integration)
[](https://scrutinizer-ci.com/g/webtoolsnz/laravel-json-schema-request/?branch=master)
[](https://scrutinizer-ci.com/g/webtoolsnz/laravel-json-schema-request/?branch=master)
Laravels [Form Request Validation](https://laravel.com/docs/7.x/validation#form-request-validation) for JSON Schema documents
Installation
--------------
```bash
composer require webtoolsnz/laravel-json-schema-request
```
Usage
------
The development experience is identical to Laravel's Form Request Validation, except instead of writing Laravel validation rules, you write a [JSON Schema](https://json-schema.org/).
You can create a new request using the `make:json-request` command
```bash
artisan make:json-request MyJsonRequest
```
You will now have new request class `App\Http\Requests\MyJsonRequest`, Below you can see a basic example schema.
```php
'object',
'properties' => [
'first_name' => ['type' => 'string'],
'last_name' => ['type' => 'string'],
'email' => ['type' => 'string', 'format' => 'email'],
],
'required' => ['first_name', 'last_name', 'email'],
'additionalProperties' => false,
];
}
}
```
Once you have a `JsonSchemaRequest` object, all you need to do is type-hint the request on your controller method.
The incoming form request is validated before the controller method is called.
```php
public function store(MyJsonRequest $request)
{
// The incoming request is valid...
// Retrieve the validated input data...
$validated = $request->validated();
}
```
License
-------
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.