|
1
|
|
|
<?php namespace Arcanesoft\Blog\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\Blog\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' => 'Blog Moderators', |
|
27
|
|
|
'description' => 'The Blog moderators role.', |
|
28
|
|
|
'is_locked' => true, |
|
29
|
|
|
],[ |
|
30
|
|
|
'name' => 'Blog Authors', |
|
31
|
|
|
'description' => 'The Blog authors role.', |
|
32
|
|
|
'is_locked' => true, |
|
33
|
|
|
] |
|
34
|
|
|
]); |
|
35
|
|
|
|
|
36
|
|
|
$this->syncAdminRole(); |
|
37
|
|
|
$this->syncRoles(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
41
|
|
|
| Other Functions |
|
42
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
43
|
|
|
*/ |
|
44
|
|
|
/** |
|
45
|
|
|
* Sync the roles. |
|
46
|
|
|
* |
|
47
|
|
|
* @todo: Refactor this method |
|
48
|
|
|
*/ |
|
49
|
|
|
private function syncRoles() |
|
50
|
|
|
{ |
|
51
|
|
|
$permissions = Permission::all(); |
|
52
|
|
|
$roles = [ |
|
53
|
|
|
'blog-moderators' => 'blog.', |
|
54
|
|
|
'blog-authors' => 'blog.posts.', |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
foreach ($roles as $roleSlug => $permissionSlug) { |
|
58
|
|
|
/** @var \Arcanesoft\Auth\Models\Role $role */ |
|
59
|
|
|
$role = Role::where('slug', $roleSlug)->first(); |
|
60
|
|
|
$ids = $permissions->filter(function (Permission $permission) use ($permissionSlug) { |
|
61
|
|
|
return starts_with($permission->slug, $permissionSlug); |
|
62
|
|
|
})->lists('id')->toArray(); |
|
63
|
|
|
|
|
64
|
|
|
$role->permissions()->sync($ids); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|