Set Data on a Fluent Instance in Laravel 11.36

This week, the Laravel team released v11.36, which includes a chainable Fluent::set() method, a default global alias for the new Uri class, and more. Fluent set() Method Steve Bauman contributed a Fluent::set() method, which adds a chainable method that supports dot notation to set deeply nested attributes: $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 The implementation uses La

Set Data on a Fluent Instance in Laravel 11.36


Click the link to join the registration on WhatsApp: https://chat.whatsapp.com/KThkuZlWaTcCu3iJHGBmLM


Click the link to join the registration on WhatsApp: https://chat.whatsapp.com/KThkuZlWaTcCu3iJHGBmLM


Click the link to join the registration on WhatsApp: https://chat.whatsapp.com/KThkuZlWaTcCu3iJHGBmLM

Set Data on a Fluent Instance in Laravel 11.36

This week, the Laravel team released v11.36, which includes a chainable Fluent::set() method, a default global alias for the new Uri class, and more.

Fluent set() Method

Steve Bauman contributed a Fluent::set() method, which adds a chainable method that supports dot notation to set deeply nested attributes:

$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

The implementation uses Laravel's data_set() function, which is a useful helper to work with nested array data:

$data = ['products' => ['desk' => ['price' => 100]]];
 
data_set($data, 'products.desk.price', 200);
data_get($data, 'products.desk.price'); // 200

For further details on setting data on a fluent instance, see Pull Request #53946.

Uri and UriQueryString implement Stringable

Luke Kuzmish contributed by adding the Stringable interface to the Uri and UriQueryString classes. These classes already implemented the Stringable interface, which is simply the __toString() magic method:

use Illuminate\Support\Uri;

$uri = Uri::of('https://laravel.com')
    ->withQuery(['name' => 'Taylor'])
    ->withPath('/docs/installation')
    ->withFragment('hello-world');

// https://laravel.com/docs/installation?name=Taylor#hello-world
(string) $uri;

See our post on Laravel v11.35's URI Parsing and Mutation features to learn more.

Uri Added as a Default, Global Alias

Jason McCreary added the new Uri class as a default global alias. That means you can access the Uri class directly without the Illuminate\Support namespace:

$uri = Uri::of('https://laravel.com')->withQuery(['name' => 'Taylor']);

See Pull Request #53884 for details.

Release notes

You can see the complete list of new features and updates below and the diff between 11.35.0 and 11.36.0 on GitHub. The following release notes are directly from the changelog:

v11.36.0


The post Set Data on a Fluent Instance in Laravel 11.36 appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow

Keep advertising to get more people

You could reach thousands of more people for every ₦1,000 you spend. https://doacweb.com/advertising

Adverts on doacWeb can be informative, educative or persuasive in nature.

doacWeb Ads is always directed at a broad audience (reaching thousands of people day by day), not few individuals — it deliver your advert to the target audience at the same time. Putting your offer in front of the right people — who have the money and interest in what you sell.

doacWeb Advertising gives you advantage as adverts passes through https://doacweb.com to the internet, reaching millions of people over the internet, and to grow your audience.

Grow your business, Be known, Boost your visibility, Drive engagements, Get new customers and Increase sales.

doacWeb acts as a global advertising media, to let people — individuals — and businesses, to promote and reach more interested people.

Get Started.

WhatsApp: 09031633831

Email: info@doacweb.com
Keep advertising to get more people

You could reach thousands of more people for every ₦1,000 you spend. https://doacweb.com/advertising

Adverts on doacWeb can be informative, educative or persuasive in nature.

doacWeb Ads is always directed at a broad audience (reaching thousands of people day by day), not few individuals — it deliver your advert to the target audience at the same time. Putting your offer in front of the right people — who have the money and interest in what you sell.

doacWeb Advertising gives you advantage as adverts passes through https://doacweb.com to the internet, reaching millions of people over the internet, and to grow your audience.

Grow your business, Be known, Boost your visibility, Drive engagements, Get new customers and Increase sales.

doacWeb acts as a global advertising media, to let people — individuals — and businesses, to promote and reach more interested people.

Get Started.

WhatsApp: 09031633831

Email: info@doacweb.com
Keep advertising to get more people

You could reach thousands of more people for every ₦1,000 you spend. https://doacweb.com/advertising

Adverts on doacWeb can be informative, educative or persuasive in nature.

doacWeb Ads is always directed at a broad audience (reaching thousands of people day by day), not few individuals — it deliver your advert to the target audience at the same time. Putting your offer in front of the right people — who have the money and interest in what you sell.

doacWeb Advertising gives you advantage as adverts passes through https://doacweb.com to the internet, reaching millions of people over the internet, and to grow your audience.

Grow your business, Be known, Boost your visibility, Drive engagements, Get new customers and Increase sales.

doacWeb acts as a global advertising media, to let people — individuals — and businesses, to promote and reach more interested people.

Get Started.

WhatsApp: 09031633831

Email: info@doacweb.com