Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mawuva/laravel-custom-form-request
Custom form request for laravel's projects provides with form data sanitization and api form request extension
https://github.com/mawuva/laravel-custom-form-request
Last synced: 7 days ago
JSON representation
Custom form request for laravel's projects provides with form data sanitization and api form request extension
- Host: GitHub
- URL: https://github.com/mawuva/laravel-custom-form-request
- Owner: mawuva
- License: mit
- Created: 2021-06-12T19:50:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-24T21:53:11.000Z (over 3 years ago)
- Last Synced: 2024-04-02T10:58:37.925Z (8 months ago)
- Language: PHP
- Homepage: https://packagist.org/packages/mawuekom/laravel-custom-form-request
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Custom Form Request
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:
```bash
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](https://github.com/mawuva/laravel-request-sanitizer) for more informations```php
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](https://github.com/mawuva/laravel-api-form-request)```php
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](LICENSE.md) for more information.