Skip to main content

Overview

The RequestBody helper extracts and manipulates parameters from a Laravel Request body. It supports JSON, form-data, multipart, raw body content, and works with any HTTP method (GET, POST, PUT, PATCH, DELETE, etc.). It excludes query parameters and route parameters by default.

Class Reference

Methods

get()

Extract parameters from request body without query params or route params.
Request
required
The Laravel Request instance
string|array|null
default:"null"
  • null: Return all body parameters
  • string: Return single parameter (supports dot notation)
  • array: Return multiple parameters
array
default:"[]"
Configuration options:
mixed
  • Returns array when keys is null or array
  • Returns mixed when keys is a string

Example Usage


all()

Explicit alias to get all parameters from request body.
Request
required
The Laravel Request instance
array
default:"[]"
Configuration options (same as get() method)
array
All body parameters as an associative array

Example Usage


only()

Get a single parameter with default value.
Request
required
The Laravel Request instance
string
required
The parameter key (supports dot notation)
mixed
default:"null"
Default value if key not found
array
default:"[]"
Additional configuration options
mixed
The parameter value or default

Example Usage


pick()

Get multiple specific parameters.
Request
required
The Laravel Request instance
array
required
Array of keys to extract (supports dot notation)
array
default:"[]"
Configuration options
array
Associative array with only specified keys

Example Usage


require()

Validate that required keys exist and return them (throws exception if missing).
Request
required
The Laravel Request instance
array
required
Array of required keys (supports dot notation)
array
default:"[]"
Configuration options
array
Associative array with required keys
\InvalidArgumentException
Thrown when one or more required keys are missing

Example Usage


Type Casting

The casts option supports automatic type conversion:

Supported Cast Types

cast
Convert to integer
cast
Convert to float
cast
Convert to boolean
cast
Convert to string
cast
Convert to array
cast
Parse JSON string to array
cast
Convert to Carbon date instance
cast
Convert to Carbon using specific format (e.g., date:Y-m-d)
cast
Custom transformation function

Type Casting Examples


Filtering Options

Only Specific Keys

Exclude Keys

Drop Internal Fields


String Normalization

Trim Strings

Empty to Null


Supported Content Types

JSON (application/json)

Form Data (application/x-www-form-urlencoded)

Multipart (multipart/form-data)

Raw Content


Complete Example