only method

Map<String, dynamic> only(
  1. List<String> keys
)

Get only the specified fields from validated data.

Creates a new map containing only the fields specified in keys. Fields that don't exist in the validated data are simply omitted from the result (no errors are thrown).

This is useful for extracting a subset of validated data for specific operations, like passing only certain fields to a model.

Example:

final formRequest = CreateUserRequest();
await formRequest.validate(request);

// Get only login credentials
final credentials = formRequest.only(['email', 'password']);
await Auth.attempt(credentials);

// Get only profile fields
final profile = formRequest.only(['name', 'bio', 'avatar']);
await user.updateProfile(profile);

Parameters:

  • keys: List of field names to include in the result

Returns: A new map containing only the specified fields

Implementation

Map<String, dynamic> only(List<String> keys) {
  if (_validatedData == null) return {};
  final result = <String, dynamic>{};
  for (final key in keys) {
    if (_validatedData!.containsKey(key)) {
      result[key] = _validatedData![key];
    }
  }
  return result;
}