1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Afrittella\BackProject\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Afrittella\BackProject\Http\Requests\RoleAdd; |
6
|
|
|
use Afrittella\BackProject\Http\Requests\RoleEdit; |
7
|
|
|
use Afrittella\BackProject\Repositories\Permissions; |
8
|
|
|
use Afrittella\BackProject\Repositories\Roles; |
9
|
|
|
use Prologue\Alerts\Facades\Alert; |
10
|
|
|
|
11
|
|
View Code Duplication |
class RolesController extends Controller |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
public function __construct() |
14
|
|
|
{ |
15
|
|
|
$this->middleware('admin'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function index(Roles $roles) |
19
|
|
|
{ |
20
|
|
|
return view('back-project::roles.index')->with('roles', $roles->transform($roles->all())); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function edit(Roles $roles, Permissions $permissions, $id) |
24
|
|
|
{ |
25
|
|
|
return view('back-project::roles.edit')->with('role', $roles->find($id))->with('permissions', $permissions->all()); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function update(RoleEdit $request, Roles $roles, $id) |
29
|
|
|
{ |
30
|
|
|
$role = $roles->update($request->all(), $id); |
|
|
|
|
31
|
|
|
|
32
|
|
|
Alert::add('success', trans('back-project::crud.model_updated', ['model' => trans('back-project::roles.role')]))->flash(); |
33
|
|
|
|
34
|
|
|
return redirect(route('bp.roles.index')); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function create(Permissions $permissions) |
38
|
|
|
{ |
39
|
|
|
return view('back-project::roles.create')->with('permissions', $permissions->all()); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function store(RoleAdd $request, Roles $roles) |
43
|
|
|
{ |
44
|
|
|
$role = $roles->create($request->all()); |
|
|
|
|
45
|
|
|
|
46
|
|
|
Alert::add('success', trans('back-project::crud.model_created', ['model' => trans('back-project::roles.role')]))->flash(); |
47
|
|
|
|
48
|
|
|
return redirect(route('bp.roles.index')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function delete(Roles $roles, $id) |
52
|
|
|
{ |
53
|
|
|
$roles->delete($id); |
54
|
|
|
|
55
|
|
|
Alert::add('success', trans('back-project::crud.model_deleted', ['model' => trans('back-project::roles.role')]))->flash(); |
56
|
|
|
|
57
|
|
|
return back(); |
58
|
|
|
} |
59
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.