1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Faker\Factory as Faker; |
4
|
|
|
use Illuminate\Database\Seeder; |
5
|
|
|
use JobApis\JobsToMail\Models\User; |
6
|
|
|
use JobApis\JobsToMail\Models\CustomDatabaseNotification as Notification; |
7
|
|
|
use JobApis\JobsToMail\Models\Search; |
8
|
|
|
use JobApis\JobsToMail\Models\Token; |
9
|
|
|
|
10
|
|
|
class TestingDatabaseSeeder extends Seeder |
11
|
|
|
{ |
12
|
|
|
public function run() |
13
|
|
|
{ |
14
|
|
|
$this->faker = Faker::create(); |
|
|
|
|
15
|
|
|
$this->createActiveUsers(); |
16
|
|
|
$this->createDeletedUsers(); |
17
|
|
|
$this->createUnconfirmedUsers(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
private function createActiveUsers($num = 10) |
21
|
|
|
{ |
22
|
|
|
return factory(User::class, $num) |
23
|
|
|
->states('active') |
24
|
|
|
->create() |
25
|
|
|
->each(function(User $user) { |
26
|
|
|
$user->tokens()->save( |
27
|
|
|
factory(Token::class)->make() |
28
|
|
|
); |
29
|
|
|
})->each(function(User $user) { // Create searches |
30
|
|
|
factory(Search::class, rand(1, 3))->create([ |
31
|
|
|
'user_id' => $user->id |
32
|
|
|
])->each(function(Search $search) { // Create notifications |
33
|
|
|
factory(Notification::class, rand(1, 3))->create([ |
34
|
|
|
'notifiable_id' => $search->user_id, |
35
|
|
|
'search_id' => $search->id, |
36
|
|
|
]); |
37
|
|
|
}); |
38
|
|
|
}); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function createDeletedUsers($num = 10) |
42
|
|
|
{ |
43
|
|
|
return factory(User::class, $num) |
44
|
|
|
->states('active', 'deleted') |
45
|
|
|
->create() |
46
|
|
|
->each(function(User $user) { |
47
|
|
|
$user->tokens()->save( |
48
|
|
|
factory(Token::class)->make() |
49
|
|
|
); |
50
|
|
|
}); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function createUnconfirmedUsers($num = 10) |
54
|
|
|
{ |
55
|
|
|
return factory(User::class, $num) |
56
|
|
|
->create() |
57
|
|
|
->each(function(User $user) { |
58
|
|
|
$user->tokens()->save( |
59
|
|
|
factory(Token::class)->make() |
60
|
|
|
); |
61
|
|
|
}); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: