Articles Snippets Projects

Creating Multiple Eloquent Models with an Incremental Index

User::factory()
    ->count(10)
    ->state(new Sequence(function () {
        static $i = 1;

        return ['name' => 'User '.$i++];
    }))
    ->create();