|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pratiksh\Adminetic\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Cache; |
|
6
|
|
|
use Pratiksh\Adminetic\Contracts\PermissionRepositoryInterface; |
|
7
|
|
|
use Pratiksh\Adminetic\Http\Requests\PermissionRequest; |
|
8
|
|
|
use Pratiksh\Adminetic\Models\Admin\Permission; |
|
9
|
|
|
use Pratiksh\Adminetic\Models\Admin\Role; |
|
10
|
|
|
|
|
11
|
|
|
class PermissionRepository implements PermissionRepositoryInterface |
|
12
|
|
|
{ |
|
13
|
|
|
// Permission Index |
|
14
|
|
|
public function indexPermission() |
|
15
|
|
|
{ |
|
16
|
|
|
$permissions = config('adminetic.caching', true) |
|
17
|
|
|
? (Cache::has('permissions') ? Cache::get('permissions') : Cache::rememberForever('permissions', function () { |
|
18
|
|
|
return Permission::with('role')->get(); |
|
19
|
|
|
})) |
|
20
|
|
|
: Permission::with('role')->get(); |
|
21
|
|
|
|
|
22
|
|
|
return compact('permissions'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
// Permission Create |
|
26
|
|
|
public function createPermission() |
|
27
|
|
|
{ |
|
28
|
|
|
$roles = Cache::get('roles', Role::all(['id', 'name'])); |
|
29
|
|
|
|
|
30
|
|
|
return compact('roles'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// Permission Store |
|
34
|
|
|
public function storePermission(PermissionRequest $request) |
|
35
|
|
|
{ |
|
36
|
|
|
Permission::create($request->validated()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// Permission Show |
|
40
|
|
|
public function showPermission(Permission $permission) |
|
41
|
|
|
{ |
|
42
|
|
|
return compact('permission'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// Permission Edit |
|
46
|
|
|
public function editPermission(Permission $permission) |
|
47
|
|
|
{ |
|
48
|
|
|
$roles = Cache::get('roles', Role::all(['id', 'name'])); |
|
49
|
|
|
|
|
50
|
|
|
return compact('permission', 'roles'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// Permission Update |
|
54
|
|
|
public function updatePermission(PermissionRequest $request, Permission $permission) |
|
55
|
|
|
{ |
|
56
|
|
|
$permission->update($request->validated()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// Permission Destroy |
|
60
|
|
|
public function destroyPermission(Permission $permission) |
|
61
|
|
|
{ |
|
62
|
|
|
$permission->delete(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|