|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
4
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
5
|
|
|
|
|
6
|
|
|
class InitializeReports extends Migration |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Run the migrations. |
|
10
|
|
|
* |
|
11
|
|
|
* @return void |
|
12
|
|
|
*/ |
|
13
|
|
|
public function up() |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Insert the permissions related to this module. |
|
17
|
|
|
*/ |
|
18
|
|
|
DB::table('permissions')->insert( |
|
19
|
|
|
[ |
|
20
|
|
|
/** |
|
21
|
|
|
* Reporting model permissions. |
|
22
|
|
|
*/ |
|
23
|
|
|
[ |
|
24
|
|
|
'name' => 'find', |
|
25
|
|
|
'model' => 'reports', |
|
26
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
27
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
28
|
|
|
], |
|
29
|
|
|
[ |
|
30
|
|
|
'name' => 'search', |
|
31
|
|
|
'model' => 'reports', |
|
32
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
33
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
34
|
|
|
], |
|
35
|
|
|
[ |
|
36
|
|
|
'name' => 'list', |
|
37
|
|
|
'model' => 'reports', |
|
38
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
39
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
40
|
|
|
], |
|
41
|
|
|
[ |
|
42
|
|
|
'name' => 'findby', |
|
43
|
|
|
'model' => 'reports', |
|
44
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
45
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
46
|
|
|
], |
|
47
|
|
|
[ |
|
48
|
|
|
'name' => 'first', |
|
49
|
|
|
'model' => 'reports', |
|
50
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
51
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
52
|
|
|
], |
|
53
|
|
|
[ |
|
54
|
|
|
'name' => 'paginate', |
|
55
|
|
|
'model' => 'reports', |
|
56
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
57
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
58
|
|
|
], |
|
59
|
|
|
[ |
|
60
|
|
|
'name' => 'paginateby', |
|
61
|
|
|
'model' => 'reports', |
|
62
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
63
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
64
|
|
|
], |
|
65
|
|
|
[ |
|
66
|
|
|
'name' => 'admin_count', |
|
67
|
|
|
'model' => 'reports', |
|
68
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
69
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
70
|
|
|
] |
|
71
|
|
|
] |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Assign the permissions to the admin group. |
|
76
|
|
|
*/ |
|
77
|
|
|
$permissionIds = DB::table('permissions')->whereIn('model', ['reports'])->select('id')->pluck('id'); |
|
78
|
|
|
$adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
|
79
|
|
View Code Duplication |
foreach ($permissionIds as $permissionId) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
DB::table('groups_permissions')->insert( |
|
82
|
|
|
[ |
|
83
|
|
|
'permission_id' => $permissionId, |
|
84
|
|
|
'group_id' => $adminGroupId, |
|
85
|
|
|
'created_at' => \DB::raw('NOW()'), |
|
86
|
|
|
'updated_at' => \DB::raw('NOW()') |
|
87
|
|
|
] |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Reverse the migrations. |
|
94
|
|
|
* |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
|
|
public function down() |
|
98
|
|
|
{ |
|
99
|
|
|
$permissions = DB::table('permissions')->whereIn('model', ['reports']); |
|
100
|
|
|
DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
101
|
|
|
$permissions->delete(); |
|
102
|
|
|
} |
|
103
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.