*/ class PostFactory extends Factory { /** * @return array */ public function definition(): array { $title = fake()->unique()->sentence(); $publishedAt = fake()->dateTimeBetween('-6 months', 'now'); return [ 'user_id' => User::factory(), 'category_id' => Category::factory(), 'title' => rtrim($title, '.'), 'slug' => Str::slug($title), 'excerpt' => fake()->sentence(20), 'body' => implode("\n\n", fake()->paragraphs(6)), 'status' => PostStatus::Published, 'published_at' => $publishedAt, 'meta_title' => null, 'meta_description' => null, ]; } public function draft(): static { return $this->state(fn () => [ 'status' => PostStatus::Draft, 'published_at' => null, ]); } }