*/ class PostFactory extends Factory { public function definition(): array { $title = rtrim(fake()->sentence(rand(4, 8)), '.'); return [ 'title' => $title, 'slug' => Str::slug($title) . '-' . fake()->unique()->numberBetween(1, 100000), 'excerpt' => fake()->sentence(rand(15, 25)), 'body' => implode("\n\n", fake()->paragraphs(rand(4, 7))), 'cover_image' => null, 'author_id' => User::query()->inRandomOrder()->value('id'), 'published_at' => now()->subDays(fake()->numberBetween(0, 60)), ]; } public function draft(): static { return $this->state(fn (array $attributes) => [ 'published_at' => null, ]); } }