mawuekom / laravel-custom-form-request
Custom form request for laravel's projects provides with form data sanitization and api form request extension
v1.0.0
2021-06-24 21:52 UTC
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0
- mawuekom/laravel-api-form-request: ^1.0
- mawuekom/laravel-form-request: ^1.0
- mawuekom/laravel-request-sanitizer: ^1.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
README
Custom form request for laravel's projects provides with form data sanitization and api form request extension
Installation
You can install the package via composer:
composer require mawuekom/laravel-custom-form-request
Usage
If you want to sanitize your request data before validation, you can do this...
Check on Laravel Request Sanitizer for more informations
namespace App\Http\Requests; use Mawuekom\CustomFormRequest\Requests\SanitizeFormRequest; class CreateUserRequest extends SanitizeFormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize(): bool { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { return [ 'name' => 'required|string|max:255', 'first_name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:6|confirmed', ]; } /** * Get sanitizers defined for form input * * @return array */ public function sanitizers(): array { return [ 'name' => [ Capitalize::class, ], 'first_name' => [ CapitalizeEachWords::class ] ]; } }
You can also use form request for your Rest API.
Check on API Form Request
namespace App\Http\Requests; use Mawuekom\CustomFormRequest\Requests\SanitizeApiFormRequest; class CreateUserRequest extends SanitizeApiFormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize(): bool { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { return [ 'name' => 'required|string|max:255', 'first_name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:6|confirmed', ]; } /** * Get sanitizers defined for form input * * @return array */ public function sanitizers(): array { return [ 'name' => [ Capitalize::class, ], 'first_name' => [ CapitalizeEachWords::class ] ]; } }
Hope this package will help you to build great things... 🏙️ Have fun 👍
License
The MIT License (MIT). Please see License File for more information.