Skip to content

[12.x] Make Fluent class iterable #56218

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

Merged
merged 3 commits into from
Jul 7, 2025

Conversation

xurshudyan
Copy link
Contributor

@xurshudyan xurshudyan commented Jul 5, 2025

Currently, while Fluent supports array-style access (ArrayAccess) and dynamic property access, it cannot be directly iterated. This gap often causes inconvenience in Laravel applications, especially when working with Eloquent attribute casting such as:

protected function casts(): array
{
    return [
        'settings' => \Illuminate\Database\Eloquent\Casts\AsFluent::class
    ];
}

Without this enhancement, developers must call ->toArray() before iterating over casted attributes

foreach ($user->settings->toArray() as $key => $value) {
    // 
}

By enabling native iteration, this change simplifies and cleans up common usage patterns, allowing

foreach ($user->settings as $key => $value) {
    //
}

@taylorotwell taylorotwell merged commit 4c7e519 into laravel:12.x Jul 7, 2025
58 of 60 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