1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Database\Factories; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Sfneal\Queries\RandomModelAttributeQuery; |
8
|
|
|
use Sfneal\Users\Models\User; |
9
|
|
|
use Sfneal\Users\Models\UserNotification; |
10
|
|
|
|
11
|
|
|
class UserNotificationFactory extends Factory |
12
|
|
|
{ |
13
|
|
|
public const TYPES = [ |
14
|
|
|
'Domain\Clients\Notifications\NewInquiryNotification', |
15
|
|
|
'Domain\Plans\Notifications\BucketChangedNotification', |
16
|
|
|
]; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The name of the factory's corresponding model. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $model = UserNotification::class; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* UserNotificationFactory constructor. |
27
|
|
|
* |
28
|
|
|
* @param null $count |
|
|
|
|
29
|
|
|
* @param Collection|null $states |
30
|
|
|
* @param Collection|null $has |
31
|
|
|
* @param Collection|null $for |
32
|
|
|
* @param Collection|null $afterMaking |
33
|
|
|
* @param Collection|null $afterCreating |
34
|
|
|
* @param null $connection |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function __construct($count = null, ?Collection $states = null, ?Collection $has = null, ?Collection $for = null, ?Collection $afterMaking = null, ?Collection $afterCreating = null, $connection = null) |
37
|
|
|
{ |
38
|
|
|
parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection); |
39
|
|
|
|
40
|
|
|
self::createUserFactories(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Define the model's default state. |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public function definition(): array |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
'user_id' => (new RandomModelAttributeQuery(User::class, 'id'))->execute(), |
52
|
|
|
'type' => $this->faker->randomElement(self::TYPES), |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Create User model factories if none exist. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
private static function createUserFactories(): void |
62
|
|
|
{ |
63
|
|
|
if (! User::query()->count()) { |
|
|
|
|
64
|
|
|
User::factory() |
65
|
|
|
->count(10) |
66
|
|
|
->create(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|