*/ class EventFactory extends Factory { private const int NB_WORDS = 5; /** * Define the model's default state. * * @return array * @throws RandomException */ public function definition(): array { static $venuesCount = config('common.seeding.model.venue.count'); static $counter = 1; static $imageProvider = app(FakerImageProvider::class)->use(config('image.faker.provider.loremflickr.type')) ->apply(); $image = new ImageStorage( config('image.storage.poster'), random_int(400, 1280), random_int(400, 960), ProviderInterface::KEYWORDS ); $poster = $imageProvider->getImage($image); // Note: numberBetween method is unsafe if you need all `venues`.`id` values be used for constraining ¯\_(ツ)_/¯ $venuesId = $counter > $venuesCount ? $this->faker->numberBetween(1, $venuesCount) : $counter++; return [ 'venue_id' => $venuesId, 'name' => Str::of($this->faker->sentence(self::NB_WORDS))->rtrim('.'), 'event_date' => $this->faker->unique()->dateTimeBetween( '-3 months', '3 months', env('APP_TIMEZONE', 'UTC') ), 'poster' => $poster, ]; } }