Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nickfla1/laravel-validated-api-requests
Simple Validation for Laravel's API requests
https://github.com/nickfla1/laravel-validated-api-requests
api composer composer-library composer-package exceptions json json-api laravel laravel-5-package laravel-framework laravel-package laravel5 php php7 rest rest-api restful restful-api validation validator
Last synced: 2 months ago
JSON representation
Simple Validation for Laravel's API requests
- Host: GitHub
- URL: https://github.com/nickfla1/laravel-validated-api-requests
- Owner: nickfla1
- License: mit
- Created: 2019-06-13T08:19:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-16T14:00:59.000Z (over 4 years ago)
- Last Synced: 2024-09-29T11:45:23.595Z (3 months ago)
- Topics: api, composer, composer-library, composer-package, exceptions, json, json-api, laravel, laravel-5-package, laravel-framework, laravel-package, laravel5, php, php7, rest, rest-api, restful, restful-api, validation, validator
- Language: PHP
- Size: 11.7 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Laravel Validated API Requests
This package allows you to use Laravel's validators on API requests.
This package is intented to be used only on API requests as the same behaviour can be achieved for regular requests using Laravel's `FormRequest`.### Installation
```sh
composer require nickfla1/laravel-validated-api-requests
```
**Requirements**| Library/Ext | Version |
| --- | --- |
| php | >=7.0.* |
| laravel/framework | >=5.5 |### Basic Usage
**Request**
```php
use Nickfla1\Utilities\ApiRequest;class FooRequest extends ApiRequest
{
/**
* Defines if the request should fire an ApiRequestException
* on validation failure.
*
* @var bool
*/
protected $firesException = true;
/**
* Define validation rules.
*
* @return array|null
*/
protected function rules()
{
return [
'foo' => 'required|string|max:30',
'bar' => 'required|mail'
];
}
}
```**Controller**
```php
class TheController extends Controller
{
public function index(FooRequest $request)
{
// If we get here the request was validated successfully!
}
}
```