laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

Provide sequence callback function with the current iteration #2569

Closed sjorsvanleeuwen closed 3 years ago

sjorsvanleeuwen commented 3 years ago

Hi,

I think it would be a nice feature to provide the current iteration to the sequence callback function. This would enable code like this:

Carbon::setTestNow(Carbon::now());

$users = User::factory()
  ->count(4)
  ->sequence(function ($iterationCount) {
    return ['created_at' => Carbon::now()->subYear()->addDays($iterationCount)];
  })
  ->create();

I think this would provide a solid and more real dataset, which would provide help testing real world scenarios.

themsaid commented 3 years ago

Feel free to open a PR