1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Carbon\Carbon; |
4
|
|
|
use Illuminate\Database\Seeder; |
5
|
|
|
use Illuminate\Support\Facades\DB; |
6
|
|
|
|
7
|
|
|
class AchievementsSeeder extends Seeder |
8
|
|
|
{ |
9
|
|
|
public function run() |
10
|
|
|
{ |
11
|
|
|
$createdAt = Carbon::now()->format('Y-m-d H:i:s'); |
12
|
|
|
|
13
|
|
|
$achievements = [ |
14
|
|
|
[ |
15
|
|
|
'id' => 1, |
16
|
|
|
'name' => 'Level 10', |
17
|
|
|
'description' => 'Reach Level 10.', |
18
|
|
|
'points' => 10, |
19
|
|
|
'created_at' => $createdAt, |
20
|
|
|
'updated_at' => $createdAt, |
21
|
|
|
'criterias' => [ |
22
|
|
|
[ |
23
|
|
|
'type' => 'reach_level', |
24
|
|
|
'name' => 'Reach level 10', |
25
|
|
|
'max_value' => 10, |
26
|
|
|
] |
27
|
|
|
], |
28
|
|
|
], |
29
|
|
|
[ |
30
|
|
|
'id' => 2, |
31
|
|
|
'name' => 'Level 20', |
32
|
|
|
'description' => 'Reach Level 20.', |
33
|
|
|
'points' => 10, |
34
|
|
|
'created_at' => $createdAt, |
35
|
|
|
'updated_at' => $createdAt, |
36
|
|
|
'criterias' => [ |
37
|
|
|
[ |
38
|
|
|
'type' => 'reach_level', |
39
|
|
|
'name' => 'Reach level 20', |
40
|
|
|
'max_value' => 20, |
41
|
|
|
] |
42
|
|
|
], |
43
|
|
|
], |
44
|
|
|
[ |
45
|
|
|
'id' => 3, |
46
|
|
|
'name' => 'Level 30', |
47
|
|
|
'description' => 'Reach Level 30.', |
48
|
|
|
'points' => 10, |
49
|
|
|
'created_at' => $createdAt, |
50
|
|
|
'updated_at' => $createdAt, |
51
|
|
|
'criterias' => [ |
52
|
|
|
[ |
53
|
|
|
'type' => 'reach_level', |
54
|
|
|
'name' => 'Reach level 30', |
55
|
|
|
'max_value' => 30, |
56
|
|
|
] |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
[ |
60
|
|
|
'id' => 4, |
61
|
|
|
'name' => '50 Quests Completed', |
62
|
|
|
'description' => 'Complete 50 quests.', |
63
|
|
|
'points' => 10, |
64
|
|
|
'created_at' => $createdAt, |
65
|
|
|
'updated_at' => $createdAt, |
66
|
|
|
'criterias' => [ |
67
|
|
|
[ |
68
|
|
|
'type' => 'complete_quests', |
69
|
|
|
'name' => 'Complete 50 quests', |
70
|
|
|
'max_value' => 50, |
71
|
|
|
] |
72
|
|
|
], |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
foreach ($achievements as $achievement) { |
77
|
|
|
$this->createAchievement($achievement); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function createAchievement(array $achievement) |
82
|
|
|
{ |
83
|
|
|
DB::table('achievements')->insert( |
84
|
|
|
array_only($achievement, ['id', 'name', 'description', 'points', 'created_at', 'updated_at']) |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
foreach ($achievement['criterias'] as $criteria) { |
88
|
|
|
DB::table('achievement_criterias')->insert( |
89
|
|
|
array_merge($criteria, ['achievement_id' => $achievement['id']]) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|