*/ class ProjectFactory extends Factory { protected $model = Project::class; /** * @return array */ public function definition(): array { $title = rtrim(fake()->unique()->catchPhrase(), '.'); $status = fake()->randomElement(ProjectStatus::cases()); return [ 'title' => $this->eachLocale(fn (string $l) => "{$title} ({$l})"), 'slug' => $this->eachLocale(fn (string $l) => Str::slug("{$title}-{$l}")), 'tagline' => $this->eachLocale(fn () => fake()->sentence(8)), 'description' => $this->eachLocale(fn () => '

'.implode('

', fake()->paragraphs(3)).'

'), 'decisions' => $this->eachLocale(fn () => '

'.fake()->paragraph().'

'), 'postmortem' => null, 'meta_title' => $this->eachLocale(fn () => Str::limit($title, 55, '')), 'meta_description' => $this->eachLocale(fn () => fake()->sentence(14)), 'status' => $status, 'demo_url' => fake()->optional()->url(), 'is_featured' => fake()->boolean(20), 'needs_help' => fake()->boolean(30), 'started_at' => fake()->dateTimeBetween('-3 years'), 'published_at' => now()->subDays(fake()->numberBetween(1, 400)), 'position' => fake()->numberBetween(0, 20), ]; } public function published(): static { return $this->state(fn () => ['published_at' => now()->subDay()]); } public function draft(): static { return $this->state(fn () => ['published_at' => null]); } public function active(): static { return $this->state(fn () => ['status' => ProjectStatus::Active]); } public function needingHelp(): static { return $this->state(fn () => [ 'needs_help' => true, 'status' => ProjectStatus::Active, ]); } /** * A finished project with the write-up that makes it worth reading — the * kind of content a commercial consultancy cannot publish. */ public function withPostmortem(): static { return $this->state(fn () => [ 'status' => ProjectStatus::Archived, 'ended_at' => fake()->dateTimeBetween('-1 year'), 'postmortem' => $this->eachLocale( fn () => '

'.implode('

', fake()->paragraphs(2)).'

', ), ]); } /** @return array */ protected function eachLocale(callable $value): array { return collect(array_keys(config('locales.supported'))) ->mapWithKeys(fn (string $l) => [$l => $value($l)]) ->all(); } }