Skip to content

Commit a6d36e8

Browse files
[12.x] document change in Eloquent Collection partition behavior (#10344)
* document change in Eloquent Collection partition behavior document the code change in laravel/framework#53304 * Update collections.md * Update eloquent-collections.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 67a890f commit a6d36e8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

collections.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,9 @@ $equalOrAboveThree->all();
20952095
// [3, 4, 5, 6]
20962096
```
20972097

2098+
> [!NOTE]
2099+
> This method's behavior is modified when interacting with [Eloquent collections](/docs/{{version}}/eloquent-collections#method-partition).
2100+
20982101
<a name="method-percentage"></a>
20992102
#### `percentage()` {.collection-method}
21002103

eloquent-collections.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ In addition, the `Illuminate\Database\Eloquent\Collection` class provides a supe
8080
[makeVisible](#method-makeVisible)
8181
[makeHidden](#method-makeHidden)
8282
[only](#method-only)
83+
[partition](#method-partition)
8384
[setVisible](#method-setVisible)
8485
[setHidden](#method-setHidden)
8586
[toQuery](#method-toquery)
@@ -237,6 +238,19 @@ The `only` method returns all of the models that have the given primary keys:
237238
$users = $users->only([1, 2, 3]);
238239
```
239240

241+
<a name="method-partition"></a>
242+
#### `partition` {.collection-method}
243+
244+
The `partition` method returns an instance of `Illuminate\Support\Collection` containing `Illuminate\Database\Eloquent\Collection` collection instances:
245+
246+
```php
247+
$partition = $users->partition(fn ($user) => $user->age > 18);
248+
249+
dump($partition::class); // Illuminate\Support\Collection
250+
dump($partition[0]::class); // Illuminate\Database\Eloquent\Collection
251+
dump($partition[1]::class); // Illuminate\Database\Eloquent\Collection
252+
```
253+
240254
<a name="method-setVisible"></a>
241255
#### `setVisible($attributes)` {.collection-method}
242256

0 commit comments

Comments
 (0)