1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Seeder; |
4
|
|
|
use App\Models\Manager; |
5
|
|
|
use App\Models\User; |
6
|
|
|
use App\Models\JobPoster; |
7
|
|
|
use App\Models\Applicant; |
8
|
|
|
|
9
|
|
|
class DevSeeder extends Seeder |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* This seeder connects all manager objects to this user. |
13
|
|
|
* Note: all seeded users have 'password' for a password. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $managerEmail = '[email protected]'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This seeder attaches all applicant objects to this user. |
21
|
|
|
* Note: all seeded users have 'password' for a password. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $applicantEmail = '[email protected]'; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Run the database seeds. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function run() |
35
|
|
|
{ |
36
|
|
|
$managerUser = User::where('email', $this->managerEmail)->first(); |
37
|
|
|
// Create the test manager if it does not exist yet |
38
|
|
|
if ($managerUser === null) { |
39
|
|
|
$managerUser = factory(User::class)->state('manager')->create(['email' => '[email protected]']); |
40
|
|
|
$managerUser->manager()->save(factory(Manager::class)->create([ |
41
|
|
|
'user_id' => $managerUser->id |
42
|
|
|
])); |
43
|
|
|
} |
44
|
|
|
//Always add new jobs to the test manager |
45
|
|
|
$managerUser->manager->job_posters()->save(factory(JobPoster::class)->state('published')->create([ |
46
|
|
|
'manager_id' => $managerUser->manager->id |
47
|
|
|
])); |
48
|
|
|
$managerUser->manager->job_posters()->save(factory(JobPoster::class)->state('unpublished')->create([ |
49
|
|
|
'manager_id' => $managerUser->manager->id |
50
|
|
|
])); |
51
|
|
|
|
52
|
|
|
$applicantUser = User::where('email', $this->applicantEmail)->first(); |
53
|
|
|
if ($applicantUser === null) { |
54
|
|
|
$applicantUser = factory(User::class)->state('applicant')->create([ |
55
|
|
|
'email' => $this->applicantEmail |
56
|
|
|
]); |
57
|
|
|
$applicantUser->applicant()->save(factory(Applicant::class)->create([ |
58
|
|
|
'user_id' => $applicantUser->id |
59
|
|
|
])); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|