*/ class ActivityLogFactory extends Factory { protected $model = ActivityLog::class; /** * @return array */ public function definition(): array { return [ 'type' => fake()->randomElement(ActivityTypeEnum::cases()), 'message' => fake()->sentence(4), 'context' => null, 'subject_type' => null, 'subject_id' => null, 'logged_at' => now(), ]; } public function type(ActivityTypeEnum $type): static { return $this->state(['type' => $type]); } public function loggedAt(Carbon $loggedAt): static { return $this->state(['logged_at' => $loggedAt]); } public function for_subject(Model $subject): static { return $this->state([ 'subject_type' => $subject->getMorphClass(), 'subject_id' => $subject->getKey(), ]); } }