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 helper #50848

Merged
merged 3 commits into from
Apr 1, 2024
Merged

Conversation

PhiloNL
Copy link
Contributor

@PhiloNL PhiloNL commented Mar 29, 2024

The fluent helper seems to be a great addition to the collect helper when working with multi-dimension arrays and people seem to like it and suggested to PR it into the core:

$data = [
    'user' => [
        'name' => 'Philo',
        'address' => [
            'city' => 'Amsterdam',
            'country' => 'Netherlands',
        ]  
    ],
    'posts' => [
        [
            'title' => 'Post 1',                
        ],
        [
            'title' => 'Post 2',               
        ]
    ]
];

❌ collect($data)->get('user');
✅ fluent($data)->user

❌ collect($data)->get('user')['name'];
✅ fluent($data)->get('user.name');

❌ collect(collect($data)->get('posts'))->pluck('title');
✅ fluent($data)->collect('posts')->pluck('title');

❌ json_encode(collect($data)->get('user')['address']);
✅ fluent($data)->scope('user.address')->toJson();

@taylorotwell taylorotwell merged commit c215697 into laravel:11.x Apr 1, 2024
28 checks passed
@PhiloNL PhiloNL deleted the feature/fluent-helper branch April 2, 2024 16:27
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.

None yet

2 participants