Skip to content

Add dot notation access to Http\Client\Request::data() #55757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 12.x
Choose a base branch
from

Conversation

d3jn
Copy link
Contributor

@d3jn d3jn commented May 16, 2025

Greetings!

This PR introduces a backwards-compatible enhancement to the Illuminate\Http\Client\Request::data() method by adding $key parameter. This allows access to specific parts of the request data using "dot" notation.

This behavior is consistent with conventions used across the framework for methods that interact with input, request or response data. It enables conventional access to request payloads (for example, when logging requests or writing HTTP client-based tests):

// Before (old)
$title = Arr::get($request, 'message.title');
// or
$title = $request['message']['title'] ?? null;

// After (new)
$title = $request->data('message.title');

The Request class already supports similar access patterns for headers via the header($key) method. Since the word "data" can serve both as singular and plural I feel like this change also preserves naming consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant