Skip to content

[12.x] document change in Eloquent Collection partition behavior #10003

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,9 @@ The `partition` method may be combined with PHP array destructuring to separate

// [3, 4, 5, 6]

> [!NOTE]
> This method's behavior is modified when using [Eloquent Collections](/docs/{{version}}/eloquent-collections#method-partition).

<a name="method-percentage"></a>
#### `percentage()` {.collection-method}

Expand Down
14 changes: 14 additions & 0 deletions eloquent-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ In addition, the `Illuminate\Database\Eloquent\Collection` class provides a supe
[makeVisible](#method-makeVisible)
[makeHidden](#method-makeHidden)
[only](#method-only)
[partition](#method-partition)
[setVisible](#method-setVisible)
[setHidden](#method-setHidden)
[toQuery](#method-toquery)
Expand Down Expand Up @@ -195,6 +196,19 @@ The `only` method returns all of the models that have the given primary keys:

$users = $users->only([1, 2, 3]);

<a name="method-partition"></a>
#### `partition` {.collection-method}

The `partition` method returns a base Collection of Eloquent Collections:

```php
$partition = $users->partition(fn ($user) => $user->age > 18);

dump($partition::class); // Illuminate\Support\Collection
dump($partition[0]::class); // Illuminate\Database\Eloquent\Collection
dump($partition[1]::class); // Illuminate\Database\Eloquent\Collection
```

<a name="method-setVisible"></a>
#### `setVisible($attributes)` {.collection-method}

Expand Down