I have a page model and a textblock model for creating pages with as many textblocks as needed. I'm using sortable from jquery ui to sorter the textblocks by position field in migration table. So every time I'm creating a textblock the position will count + 1, starting from 1.
Now I'm setting up 2 faker factories, 1 for pages and 1 for generating dummy textblocks on the pages. I'm wondering how I can count the amount of random textblocks the factory will create? So I can say every time the page factory creates a page with a few textblocks the counter won't override the amount of textblocks each page has.
$factory->define(Textblock::class, function (Faker $faker) {
return [
'page_id' => Page::all()->random()->id,
'title' => $faker->sentence(rand(2, 5)),
'summary' => $faker->text,
'position' => // how can i code this ?
'visible' => $faker->boolean($chanceOfGettingTrue = 50),
]; });