Skip to content
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

[11.x] Add Fluent::set method #53946

Merged
merged 3 commits into from
Dec 17, 2024
Merged

Conversation

stevebauman
Copy link
Contributor

@stevebauman stevebauman commented Dec 17, 2024

Description

This PR adds a chainable set method to the Support\Fluent class.

This allows a developer to use dot notation to set deeply nested attributes on the Fluent instance.

Usage

$fluent = new Fluent;

// Set basic attributes
$fluent->set('product', 'iPhone')
       ->set('version', 15)
       ->set('developer', 'Apple');

// Use dot notation for nested attributes
$fluent->set('specs.color', 'Space Black')
       ->set('specs.storage', '256GB')
       ->set('specs.price.usd', 1199);

// Retrieve values
echo $fluent->product; // "iPhone"
echo $fluent->specs['color']; // "Space Black"
echo $fluent->specs['price']['usd']; // 1199

// Retrieve values using get with dot notation
echo $fluent->get('specs.color'); // "Space Black"
echo $fluent->get('specs.price.usd'); // 1199

@taylorotwell taylorotwell merged commit 3728f3b into laravel:11.x Dec 17, 2024
40 checks passed
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