Skip to main content

Overview

BaseFormRequest extends Laravel’s FormRequest and provides enhanced validation capabilities integrated with Rest Generic Class features, including role-based field validation and database existence checks.

Basic Usage

Create a form request by extending BaseFormRequest:

Usage in Controllers

Use form requests in your controller methods:

Integration with TransformData Middleware

BaseFormRequest works seamlessly with the TransformData middleware to inject route parameters:

Custom Validation Rules

Use the package’s custom validation rules in your form requests:

Bulk Validation

For bulk operations, validate arrays of data:

Custom Error Messages

Override the messages() method to provide custom error messages:

Custom Attribute Names

Override the attributes() method for cleaner error messages:

Conditional Rules

Apply rules conditionally based on request data:

Validation with Scenarios

Use the model’s scenario system for different validation contexts:

Integration with Role-Based Validation

BaseFormRequest integrates with the FilterRequestByRole middleware to automatically validate field access based on user roles.

Complete Example

Here’s a comprehensive example combining multiple features:

Next Steps

Validation Rules

Explore custom validation rules

RestController

Using form requests in controllers

TransformData Middleware

Automatic request transformation

FilterRequestByRole

Role-based field filtering