1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace Database\Factories;
7
8use App\Libraries\MorphMap;
9use App\Models\Comment;
10use App\Models\User;
11
12class CommentFactory extends Factory
13{
14 protected $model = Comment::class;
15
16 public function definition(): array
17 {
18 return [
19 'commentable_type' => fn () => $this->faker->randomElement(Comment::COMMENTABLES),
20 'message' => fn () => $this->faker->paragraph(),
21 'user_id' => User::factory(),
22
23 // depends on commentable_type
24 'commentable_id' => fn (array $attr) => MorphMap::getClass($attr['commentable_type'])::factory(),
25 ];
26 }
27
28 public function deleted(): static
29 {
30 return $this->state(['deleted_at' => now()]);
31 }
32
33 public function reply(): static
34 {
35 return $this->for(Comment::factory(), 'parent');
36 }
37}