*/ class PostFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = Post::class; /** * Define the model's default state. * * @return array */ public function definition() { return [ 'title' => $this->faker->sentence, 'content' => $this->faker->paragraphs(3, true), 'category_id' => Category::inRandomOrder()->first()->id ?? null, 'created_at' => now(), 'updated_at' => now(), ]; } }