1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Database\Factories; |
4
|
|
|
|
5
|
|
|
use Database\Factories\Traits\ModelChanges; |
6
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
use Sfneal\Tracking\Utils\ModelAdapter; |
9
|
|
|
use Sfneal\Tracking\Utils\RandomTrackable; |
10
|
|
|
|
11
|
|
|
class TrackActivityFactory extends Factory |
12
|
|
|
{ |
13
|
|
|
use ModelChanges; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* TrackActivityFactory constructor. |
17
|
|
|
* |
18
|
|
|
* @param null $count |
|
|
|
|
19
|
|
|
* @param Collection|null $states |
20
|
|
|
* @param Collection|null $has |
21
|
|
|
* @param Collection|null $for |
22
|
|
|
* @param Collection|null $afterMaking |
23
|
|
|
* @param Collection|null $afterCreating |
24
|
|
|
* @param null $connection |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
public function __construct($count = null, |
27
|
|
|
?Collection $states = null, |
28
|
|
|
?Collection $has = null, |
29
|
|
|
?Collection $for = null, |
30
|
|
|
?Collection $afterMaking = null, |
31
|
|
|
?Collection $afterCreating = null, |
32
|
|
|
$connection = null) |
33
|
|
|
{ |
34
|
|
|
$this->model = ModelAdapter::TrackActivity(); |
35
|
|
|
parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Define the model's default state. |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function definition(): array |
44
|
|
|
{ |
45
|
|
|
$trackable = new RandomTrackable(); |
46
|
|
|
|
47
|
|
|
return [ |
48
|
|
|
'user_id' => $this->faker->randomNumber(3), |
49
|
|
|
'route' => $this->route(), |
50
|
|
|
'description' => $this->faker->text(), |
51
|
|
|
|
52
|
|
|
'model_changes' => $this->faker->randomElements($this->modelChanges()), |
|
|
|
|
53
|
|
|
'request_token' => $this->faker->uuid, |
54
|
|
|
|
55
|
|
|
'trackable_id' => $trackable->id, |
56
|
|
|
'trackable_type' => $trackable->type, |
57
|
|
|
|
58
|
|
|
'created_at' => $this->faker->date('Y-m-d H:i:s'), |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Retrieve an array of 'route' that can be used as random elements. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
protected function route(): string |
68
|
|
|
{ |
69
|
|
|
$prefixes = ['projects', 'tasks', 'reports', 'client']; |
70
|
|
|
$actions = ['store', 'update', 'delete']; |
71
|
|
|
|
72
|
|
|
return $this->faker->randomElement($prefixes).'.'.$this->faker->randomElement($actions); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|