jiinkim / laravel-deeper-sanitizer
A http request santizer for Laravel that allows you to sanitizer any format of JSON objects in Laravel Request before controllers start to deal with it
dev-main
2023-02-01 02:58 UTC
Requires
- php: ^7.3|^8.0
- illuminate/http: ^6.0|^7.0|^8.0
- symfony/http-foundation: ^4.3.4|>=5.1.3
This package is not auto-updated.
Last update: 2024-06-02 18:36:46 UTC
README
This repository is originated from arondeparon/laravel-request-sanitizer
. I gave a little change for my own use. Extra sanitizer classes are to handle more JSON payload formats.
Please check the original repo (https://github.com/ArondeParon/laravel-request-sanitizer/blob/main/README.md).
Sanitize a nested JSON object
class StoreCustomerInformationRequest extends FormRequest { use SanitizesInputs; protected $sanitizers = [ 'billing_address' => [ NestedSanitizer::class => [ 'sanitizers' => [ 'address1', 'address2', 'city', 'country' => [ Lowercase::class ], 'province', 'zip' => [ Uppercase::class, Trim::class ], 'province_code' => [ Uppercase::class ], 'country_code' => [ Uppercase::class ], ] ] ], ]; }
Sanitize an array of JSON objects
class StoreCustomerInformationRequest extends FormRequest { use SanitizesInputs; protected $sanitizers = [ 'line_items' => [ NestedArraySanitizer::class => [ 'currency' => [ Uppercase::class ], 'quantity' => [ RemoveNonNumeric::class ], 'price' => [ RemoveNonNumeric::class ], 'shipping_fee' => [ RemoveNonNumeric::class ], 'discount' => [ RemoveNonNumeric::class ], 'taxes' => [ RemoveNonNumeric::class ], ] ], ]; }