1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Schema\Blueprint; |
4
|
|
|
use Illuminate\Database\Migrations\Migration; |
5
|
|
|
|
6
|
|
View Code Duplication |
class InitializeCore extends Migration |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Run the migrations. |
10
|
|
|
* |
11
|
|
|
* @return void |
12
|
|
|
*/ |
13
|
|
|
public function up() |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Delete previous permissions. |
17
|
|
|
*/ |
18
|
|
|
DB::table('permissions')->whereIn('model', ['settings'])->delete(); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Insert the permissions related to this module. |
22
|
|
|
*/ |
23
|
|
|
DB::table('permissions')->insert( |
24
|
|
|
[ |
25
|
|
|
/** |
26
|
|
|
* Users model permissions. |
27
|
|
|
*/ |
28
|
|
|
[ |
29
|
|
|
'name' => 'save', |
30
|
|
|
'model' => 'settings', |
31
|
|
|
'created_at' => \DB::raw('NOW()'), |
32
|
|
|
'updated_at' => \DB::raw('NOW()') |
33
|
|
|
], |
34
|
|
|
[ |
35
|
|
|
'name' => 'find', |
36
|
|
|
'model' => 'settings', |
37
|
|
|
'created_at' => \DB::raw('NOW()'), |
38
|
|
|
'updated_at' => \DB::raw('NOW()') |
39
|
|
|
], |
40
|
|
|
[ |
41
|
|
|
'name' => 'search', |
42
|
|
|
'model' => 'settings', |
43
|
|
|
'created_at' => \DB::raw('NOW()'), |
44
|
|
|
'updated_at' => \DB::raw('NOW()') |
45
|
|
|
], |
46
|
|
|
[ |
47
|
|
|
'name' => 'list', |
48
|
|
|
'model' => 'settings', |
49
|
|
|
'created_at' => \DB::raw('NOW()'), |
50
|
|
|
'updated_at' => \DB::raw('NOW()') |
51
|
|
|
], |
52
|
|
|
[ |
53
|
|
|
'name' => 'findby', |
54
|
|
|
'model' => 'settings', |
55
|
|
|
'created_at' => \DB::raw('NOW()'), |
56
|
|
|
'updated_at' => \DB::raw('NOW()') |
57
|
|
|
], |
58
|
|
|
[ |
59
|
|
|
'name' => 'first', |
60
|
|
|
'model' => 'settings', |
61
|
|
|
'created_at' => \DB::raw('NOW()'), |
62
|
|
|
'updated_at' => \DB::raw('NOW()') |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
'name' => 'paginate', |
66
|
|
|
'model' => 'settings', |
67
|
|
|
'created_at' => \DB::raw('NOW()'), |
68
|
|
|
'updated_at' => \DB::raw('NOW()') |
69
|
|
|
], |
70
|
|
|
[ |
71
|
|
|
'name' => 'paginateby', |
72
|
|
|
'model' => 'settings', |
73
|
|
|
'created_at' => \DB::raw('NOW()'), |
74
|
|
|
'updated_at' => \DB::raw('NOW()') |
75
|
|
|
] |
76
|
|
|
] |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Assign the permissions to the admin group. |
81
|
|
|
*/ |
82
|
|
|
$permissionIds = DB::table('permissions')->whereIn('model', ['settings'])->select('id')->lists('id'); |
83
|
|
|
$adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
84
|
|
|
foreach ($permissionIds as $permissionId) |
85
|
|
|
{ |
86
|
|
|
DB::table('groups_permissions')->insert( |
87
|
|
|
[ |
88
|
|
|
'permission_id' => $permissionId, |
89
|
|
|
'group_id' => $adminGroupId, |
90
|
|
|
'created_at' => \DB::raw('NOW()'), |
91
|
|
|
'updated_at' => \DB::raw('NOW()') |
92
|
|
|
] |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Reverse the migrations. |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
|
|
public function down() |
103
|
|
|
{ |
104
|
|
|
$adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
105
|
|
|
$adminUserId = DB::table('users')->where('email', '[email protected]')->first()->id; |
106
|
|
|
|
107
|
|
|
DB::table('permissions')->whereIn('model', ['settings'])->delete(); |
108
|
|
|
DB::table('users_groups')->where('user_id', $adminUserId)->where('group_id', $adminGroupId)->delete(); |
109
|
|
|
} |
110
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.