sidigi / laravel-json-api-request
Fund package maintenance!
bgs
bgs-group.eu
Installs: 3 856
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- mohammedmanssour/form-request-tester: ^1.0
- orchestra/testbench: ^6.2
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-11-18 15:34:26 UTC
README
Provide some JSON API validation stuff JSON API for laravel Form requests.
Installation
You can install the package via composer:
composer require sidigi/laravel-json-api-request
Usage
Controller
public function index(UserIndexRequest $request) { $users = User::all(); return response()->json($users); }
Form Request
use Illuminate\Foundation\Http\FormRequest; use Sidigi\LaravelJsonApiRequest\Traits; class UserIndexRequest extends FormRequest { use IsJsonApiRequest; public function rules() { return $this->jsonApiRules() } //filter value ?filter[id]=1,2,3 - for all values public function valueFilterRules() { return [ 'id' => 'exists:users,id' ] } //filter value ?filter[id]=1,2,3 - for each values public function eachValueFilterRules() { return [ 'id' => 'integer' ] } }
use Illuminate\Foundation\Http\FormRequest; use Sidigi\LaravelJsonApiRequest\Traits; class UserIndexRequest extends FormRequest { use HasFilterField, HasGroupFields, HasIncludeFields, HasBasePaginationFields, HasSortFields; public function rules() { return array_merge( $this->sortRules(), // HasSortFields $this->filterRules(), //HasFilterField $this->groupRules(), //HasGroupFields $this->includeRules(), //HasIncludeFields $this->paginationRules() //HasBasePaginationFields ); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.