Skip to content

[11.x] Add FormRequest::array($key) and Fluent::array($key)#54177

Merged
taylorotwell merged 3 commits into
laravel:11.xfrom
stevebauman:request-array
Jan 13, 2025
Merged

[11.x] Add FormRequest::array($key) and Fluent::array($key)#54177
taylorotwell merged 3 commits into
laravel:11.xfrom
stevebauman:request-array

Conversation

@stevebauman
Copy link
Copy Markdown
Contributor

@stevebauman stevebauman commented Jan 13, 2025

Description

This PR add an array($key) method to both the FormRequest and Fluent instance via the InteractsWithDataTrait.

Previously, to retrieve a value from either instance as an array you had to manually cast the result yourself:

$fluent = new Fluent(['...']);

(array) $fluent->get('value');

Or use ->collect()->all():

public function store(UserRequest $request)
{
    $values = $request->collect('...')->all();

    // ...
}

Usage

This allows developers to always retrieve a value as an array:

$fluent = new Fluent(['...']);

$values = $fluent->array('value');
public function store(UserRequest $request)
{
    $values = $request->array('...');

    // ...
}

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.

2 participants