-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPermissionController.php
204 lines (169 loc) · 5.52 KB
/
PermissionController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* File name: PermissionController.php
* Last modified: 2020.05.21 at 18:10:04
* Author: SmarterVision - https://codecanyon.net/user/smartervision
* Copyright (c) 2020
*/
namespace App\Http\Controllers;
use App\DataTables\PermissionDataTable;
use App\Http\Requests;
use App\Http\Requests\CreatePermissionRequest;
use App\Http\Requests\UpdatePermissionRequest;
use App\Repositories\PermissionRepository;
use Flash;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Artisan;
use Request;
use Response;
class PermissionController extends Controller
{
/** @var PermissionRepository */
private $permissionRepository;
public function __construct(PermissionRepository $permissionRepo)
{
parent::__construct();
$this->permissionRepository = $permissionRepo;
}
/**
* Display a listing of the Permission.
*
* @param PermissionDataTable $permissionDataTable
* @return Response
*/
public function index(PermissionDataTable $permissionDataTable)
{
return $permissionDataTable->render('settings.permissions.index');
}
public function refreshPermissions(Request $request){
Artisan::call('db:seed',['--class'=> 'DemoPermissionsPermissionsTableSeeder']);
redirect()->back();
}
public function givePermissionToRole(Request $request){
if(env('APP_DEMO',false)) {
Flash::warning('This is only demo app you can\'t change this section ');
}else{
$input = Request::all();
$this->permissionRepository->givePermissionToRole($input);
}
}
public function revokePermissionToRole(Request $request){
if(env('APP_DEMO',false)) {
Flash::warning('This is only demo app you can\'t change this section ');
}else{
$input = Request::all();
$this->permissionRepository->revokePermissionToRole($input);
}
}
public function roleHasPermission(Request $request){
$input = Request::all();
//dd($input);
$result = $this->permissionRepository->roleHasPermission($input);
return json_encode($result);
}
/**
* Show the form for creating a new Permission.
*
* @return Response
*/
public function create()
{
return view('settings.permissions.create');
}
/**
* Store a newly created Permission in storage.
*
* @param CreatePermissionRequest $request
*
* @return Response
*/
public function store(CreatePermissionRequest $request)
{
if(env('APP_DEMO',false)) {
Flash::warning('This is only demo app you can\'t change this section ');
return redirect(route('permissions.index'));
}
$input = $request->all();
$permission = $this->permissionRepository->create($input);
Flash::success('Permission saved successfully.');
return redirect(route('permissions.index'));
}
/**
* Display the specified Permission.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
$permission = $this->permissionRepository->findWithoutFail($id);
if (empty($permission)) {
Flash::error('Permission not found');
return redirect(route('permissions.index'));
}
return view('settings.permissions.show')->with('permission', $permission);
}
/**
* Show the form for editing the specified Permission.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
$permission = $this->permissionRepository->findWithoutFail($id);
if (empty($permission)) {
Flash::error('Permission not found');
return redirect(route('permissions.index'));
}
return view('settings.permissions.edit')->with('permission', $permission);
}
/**
* Update the specified Permission in storage.
*
* @param int $id
* @param UpdatePermissionRequest $request
*
* @return Response
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function update($id, UpdatePermissionRequest $request)
{
if(env('APP_DEMO',false)) {
Flash::warning('This is only demo app you can\'t change this section ');
return redirect(route('permissions.index'));
}
$permission = $this->permissionRepository->findWithoutFail($id);
if (empty($permission)) {
Flash::error('Permission not found');
return redirect(route('permissions.index'));
}
$permission = $this->permissionRepository->update($request->all(), $id);
Flash::success('Permission updated successfully.');
return redirect(route('permissions.index'));
}
/**
* Remove the specified Permission from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
if(env('APP_DEMO',false)) {
Flash::warning('This is only demo app you can\'t change this section ');
return redirect(route('permissions.index'));
}
$permission = $this->permissionRepository->findWithoutFail($id);
if (empty($permission)) {
Flash::error('Permission not found');
return redirect(route('permissions.index'));
}
$this->permissionRepository->delete($id);
Flash::success('Permission deleted successfully.');
return redirect(route('permissions.index'));
}
}