1
|
|
|
<?php namespace Arcanesoft\Pages\Seeds; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Models\Role; |
4
|
|
|
use Arcanesoft\Auth\Models\Permission; |
5
|
|
|
use Arcanesoft\Auth\Seeds\RolesSeeder; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class RolesTableSeeder |
9
|
|
|
* |
10
|
|
|
* @package Arcanesoft\Pages\Seeds |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class RolesTableSeeder extends RolesSeeder |
14
|
|
|
{ |
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
16
|
|
|
| Main Functions |
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
18
|
|
|
*/ |
19
|
|
|
/** |
20
|
|
|
* Run the database seeds. |
21
|
|
|
*/ |
22
|
|
|
public function run() |
23
|
|
|
{ |
24
|
|
|
$this->seed([ |
25
|
|
|
[ |
26
|
|
|
'name' => 'Pages Moderators', |
27
|
|
|
'description' => 'The Pages moderators role.', |
28
|
|
|
'is_locked' => true, |
29
|
|
|
],[ |
30
|
|
|
'name' => 'Pages Authors', |
31
|
|
|
'description' => 'The Pages authors role.', |
32
|
|
|
'is_locked' => true, |
33
|
|
|
] |
34
|
|
|
]); |
35
|
|
|
$this->syncAdminRole(); |
36
|
|
|
$this->syncRoles(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/* ------------------------------------------------------------------------------------------------ |
40
|
|
|
| Other Functions |
41
|
|
|
| ------------------------------------------------------------------------------------------------ |
42
|
|
|
*/ |
43
|
|
|
/** |
44
|
|
|
* Sync the roles. |
45
|
|
|
* |
46
|
|
|
* @todo: Refactor this method |
47
|
|
|
*/ |
48
|
|
|
private function syncRoles() |
49
|
|
|
{ |
50
|
|
|
$permissions = Permission::all(); |
51
|
|
|
$roles = [ |
52
|
|
|
'pages-moderators' => 'pages.', |
53
|
|
|
'pages-authors' => 'pages.pages.', |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
foreach ($roles as $roleSlug => $permissionSlug) { |
57
|
|
|
/** @var \Arcanesoft\Auth\Models\Role $role */ |
58
|
|
|
$role = Role::where('slug', $roleSlug)->first(); |
59
|
|
|
$ids = $permissions->filter(function (Permission $permission) use ($permissionSlug) { |
60
|
|
|
return starts_with($permission->slug, $permissionSlug); |
61
|
|
|
})->lists('id')->toArray(); |
62
|
|
|
|
63
|
|
|
$role->permissions()->sync($ids); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|