36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\OperationLog;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<OperationLog>
|
|
*/
|
|
class OperationLogFactory extends Factory
|
|
{
|
|
protected $model = OperationLog::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$payload = $this->faker->optional()->randomElement([
|
|
['action' => 'create', 'status' => 'ok'],
|
|
['item_id' => 1, 'count' => 2],
|
|
['note' => 'sample'],
|
|
]);
|
|
|
|
return [
|
|
'ip_address' => $this->faker->ipv4(),
|
|
'user_label' => $this->faker->optional()->userName(),
|
|
'method' => $this->faker->randomElement(['POST', 'PUT', 'PATCH', 'DELETE']),
|
|
'path' => '/' . $this->faker->slug(2),
|
|
'route_name' => $this->faker->optional()->slug(2),
|
|
'status_code' => $this->faker->randomElement([200, 201, 204, 400, 403, 422, 500]),
|
|
'duration_ms' => $this->faker->numberBetween(1, 5000),
|
|
'request_payload' => $payload,
|
|
'user_agent' => $this->faker->userAgent(),
|
|
];
|
|
}
|
|
}
|