*/ class UserScoreFactory extends Factory { protected $model = UserScore::class; /** * Define the model's default state. * * @return array */ public function definition(): array { $type = UserScore::getTypeList()->random(); $user = PartyUser::query()->inRandomOrder()->first(); $time = $this->faker->dateTimeBetween('-3 years', 'now'); return [ 'type_id' => $type->id, 'cate_id' => $user->cate_id, 'user_id' => $user->id, 'title' => $this->faker->sentence, 'content' => $this->faker->paragraph, 'images' => ['https://via.placeholder.com/100x100.png', 'https://via.placeholder.com/100x100.png'], 'file' => 'https://via.placeholder.com/100x100.png', 'check_status' => CheckStatus::Success, 'check_user_id' => 1, 'check_at' => $time, 'score' => $this->faker->numberBetween(10, 100), 'created_at' => $time, ]; } public function configure(): static { return $this->afterCreating(function (UserScore $userScore) { PartyUserService::make()->incrementScore($userScore->user, $userScore->type->key, $userScore->score); }); } }