|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Database\Factories; |
|
4
|
|
|
|
|
5
|
|
|
use Database\Factories\Traits\ModelChanges; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
|
7
|
|
|
use Sfneal\Tracking\Models\TrackTraffic; |
|
8
|
|
|
|
|
9
|
|
|
class TrackTrafficFactory extends Factory |
|
10
|
|
|
{ |
|
11
|
|
|
use ModelChanges; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* The name of the factory's corresponding model. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $model = TrackTraffic::class; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Define the model's default state. |
|
22
|
|
|
* |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
public function definition(): array |
|
26
|
|
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
'user_id' => $this->faker->randomNumber(3), |
|
29
|
|
|
'session_id' => session_id(), |
|
30
|
|
|
|
|
31
|
|
|
// Application |
|
32
|
|
|
'app_version' => $this->version(), |
|
33
|
|
|
'app_environment' => $this->environment(), |
|
34
|
|
|
|
|
35
|
|
|
// Request |
|
36
|
|
|
'request_host' => $this->environment().'.example.com', |
|
37
|
|
|
'request_uri' => $this->uri(), |
|
38
|
|
|
'request_method' => $this->faker->randomElement(['GET', 'POST', 'PUT', 'DELETE']), |
|
39
|
|
|
'request_payload' => ['page' => $this->faker->randomNumber(1)], |
|
40
|
|
|
'request_browser' => null, |
|
41
|
|
|
'request_ip' => '192.168.150.51', |
|
42
|
|
|
'request_referrer' => null, |
|
43
|
|
|
'request_token' => $this->faker->uuid, |
|
44
|
|
|
|
|
45
|
|
|
// Response |
|
46
|
|
|
'response_code' => $this->faker->randomElement([200, 201, 500, 504]), |
|
47
|
|
|
'response_time' => $this->faker->randomFloat(2, 0, 10), |
|
48
|
|
|
'response_content' => null, |
|
49
|
|
|
|
|
50
|
|
|
// Agent |
|
51
|
|
|
'agent_platform' => $this->faker->randomElement(['OS X', 'Windows', 'iOS', 'AndroidOS', 'Linux']), |
|
52
|
|
|
'agent_device' => $this->faker->randomElement(['Macintosh', 'WebKit']), |
|
53
|
|
|
'agent_browser' => $this->faker->randomElement(['Chrome', 'Mozilla', 'Safari']), |
|
54
|
|
|
|
|
55
|
|
|
// Timestamp |
|
56
|
|
|
'time_stamp' => $this->faker->date('Y-m-d H:i:s'), |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Retrieve a random semantic version number. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function version(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->faker->randomDigit.'.'.$this->faker->randomDigit.'.'.$this->faker->randomDigit; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Retrieve a random application environment name. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function environment(): string |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->faker->randomElement(['production', 'development', 'staging']); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Retrieve a random request uri. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function uri(): string |
|
86
|
|
|
{ |
|
87
|
|
|
return '/'.$this->faker->randomElement([ |
|
88
|
|
|
'about', |
|
89
|
|
|
'services', |
|
90
|
|
|
'team', |
|
91
|
|
|
'portfolio', |
|
92
|
|
|
'faqs', |
|
93
|
|
|
]); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|