Skip to content

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

Merged
taylorotwell merged 3 commits intolaravel:11.xfrom
stevebauman:fluent-set
Dec 17, 2024
Merged

[11.x] Add Fluent::set method#53946
taylorotwell merged 3 commits intolaravel:11.xfrom
stevebauman:fluent-set

Conversation

@stevebauman
Copy link
Copy Markdown
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
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