*/ class AuditFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { $morphPrefix = Config::get('audit.user.morph_prefix', 'user'); return [ $morphPrefix.'_id' => function () { return User::factory()->create()->id; }, $morphPrefix.'_type' => function () { return (new User)->getMorphClass(); }, 'event' => 'updated', 'auditable_id' => function () { return User::factory()->create()->getKey(); }, 'auditable_type' => function () { return (new User)->getMorphClass(); }, 'old_values' => [], 'new_values' => [], 'url' => $this->faker->url, 'ip_address' => $this->faker->ipv4, 'user_agent' => $this->faker->userAgent, 'tags' => implode(',', $this->faker->words(4)), ]; } public function auditUser(User $user): self { return $this->state(function (array $attributes) use ($user) { $morphPrefix = Config::get('audit.user.morph_prefix', 'user'); return [ $morphPrefix.'_id' => $user->getKey(), $morphPrefix.'_type' => $user->getMorphClass(), ]; }); } public function auditFor(Model $model): self { return $this->state(function (array $attributes) use ($model) { return [ 'auditable_id' => $model->getKey(), 'auditable_type' => $model->getMorphClass(), ]; }); } }