Skip to content

Conversation

@fritz-c
Copy link
Contributor

@fritz-c fritz-c commented Sep 17, 2025

The following description of $count in a Sequence callback:

the $count property contains the total number of times the sequence will be invoked

is incorrect.

$count is equal to the number of parameters passed to the constructor.

$count is not useful for Sequences with a callback passed to the constructor, as, if there is only one callback passed, $count will always be 1. If two callbacks were passed to the constructor, it would be 2, and so on.

In tinker:

> User::factory()->count(3)->sequence(fn($s)=> ['name'=>$s->count])->make()->pluck('name')
= Illuminate\Support\Collection {#6526
    all: [
      1,
      1,
      1,
    ],
  }

The primary use for $count is one internal to the Sequence class logic, when multiple arguments are passed to the sequence constructor and the count is used to modulo the index to avoid accessing values beyond the size of the arguments array. It's hard to imagine scenarios where this value would be particularly useful as a public property, but concealing it from the documentation will at least help people avoid using it mistakenly.

I also updated the code snippet to use the syntax ->state(new Sequence( rather than ->sequence(, as that latter concept is first introduced in the lines below this snippet.

$count is not useful for Sequences used with a callback, as it will always be `1`. The only use for $count is one internal to the Sequence class logic, when an array is passed to the sequence constructor and the count is used to modulo the index to avoid accessing values beyond the size of the array.
@taylorotwell taylorotwell merged commit da03fe3 into laravel:12.x Sep 17, 2025
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