|
1
|
|
|
<?php namespace Distilleries\Expendable\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
use Distilleries\Expendable\Contracts\LayoutManagerContract; |
|
4
|
|
|
use Distilleries\Expendable\Http\Forms\Permission\PermissionForm; |
|
5
|
|
|
use Distilleries\Expendable\Http\Controllers\Backend\Base\ModelBaseController; |
|
6
|
|
|
use Distilleries\Expendable\States\FormStateTrait; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Distilleries\Expendable\Models\Permission; |
|
9
|
|
|
use Distilleries\FormBuilder\Contracts\FormStateContract; |
|
10
|
|
|
use \FormBuilder; |
|
11
|
|
|
|
|
12
|
|
|
class PermissionController extends ModelBaseController implements FormStateContract { |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use FormStateTrait; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(PermissionForm $form, Permission $model, LayoutManagerContract $layoutManager) |
|
17
|
|
|
{ |
|
18
|
|
|
parent::__construct($model, $layoutManager); |
|
19
|
|
|
$this->form = $form; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
24
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
25
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
26
|
|
|
|
|
27
|
|
|
public function getIndex() |
|
28
|
|
|
{ |
|
29
|
|
|
return redirect()->to(action('\\' . get_class($this) . '@getEdit')); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
33
|
|
|
|
|
34
|
|
|
public function postEdit(Request $request) |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
$form = FormBuilder::create(get_class($this->form), [ |
|
38
|
|
|
'model' => $this->model |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
if ($form->hasError()) |
|
42
|
|
|
{ |
|
43
|
|
|
return $form->validateAndRedirectBack(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$permissions = $request->get('permission'); |
|
47
|
|
|
$this->model->truncate(); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
foreach ($permissions as $role_id=>$permission) { |
|
51
|
|
|
|
|
52
|
|
|
foreach ($permission as $service_id) { |
|
53
|
|
|
$permModel = new $this->model; |
|
54
|
|
|
$permModel->role_id = $role_id; |
|
55
|
|
|
$permModel->service_id = $service_id; |
|
56
|
|
|
$permModel->save(); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
return redirect()->to(action('\\' . get_class($this) . '@getIndex')); |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |