Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
RoleController
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 7
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 index
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 store
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 edit
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 update
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 destroy
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Controllers\Dashboard;
4
5use App\Http\Controllers\Controller;
6use App\Http\Requests\roles\createRequest;
7use App\Http\Requests\roles\editRequest;
8use App\Models\Role;
9use App\Services\ActivityLogsService;
10use App\Services\RolesService;
11
12class RoleController extends Controller
13{
14    protected $RolesService;
15    protected $ActivityLogsService;
16
17    public function __construct(RolesService $RolesService,
18                                ActivityLogsService $ActivityLogsService) {
19                                    
20        $this->RolesService = $RolesService;
21        $this->ActivityLogsService = $ActivityLogsService;
22
23
24        $this->middleware('permissionMiddleware:read-roles')->only('index');
25        $this->middleware('permissionMiddleware:delete-roles')->only('destroy');
26        $this->middleware('permissionMiddleware:update-roles')->only(['edit', 'update']);
27        $this->middleware('permissionMiddleware:create-roles')->only(['create', 'store']);
28    }
29
30    public function index(){
31        $roles = Role::get();
32        return view('Dashboard.roles.index')->with('roles', $roles);
33    }
34
35    public function create(){
36        return view('Dashboard.roles.create');
37    }
38
39    public function store(createRequest $request){
40        $role = $this->RolesService->insert($request);
41
42        $this->ActivityLogsService->insert([
43            'subject_id'      => $role->id,
44            'subject_type'    => 'App\Models\Role',
45            'description'     => 'create',
46            'causer_id'       => auth('user')->user()->id,
47            'causer_type'     => 'App\Models\User',
48            'properties'      => null,
49        ]);
50
51        return redirect('dashboard/roles')->with('success', 'success');
52    }
53
54    public function edit($role_id){
55        $role = Role::findOrFail($role_id);
56
57        return view('Dashboard.roles.edit')->with('data', $role);
58    }
59
60    public function update($role_id, editRequest $request){
61        $role = Role::findOrFail($role_id);
62
63        $this->RolesService->update($role, $request);
64
65        $this->ActivityLogsService->insert([
66            'subject_id'      => $role_id,
67            'subject_type'    => 'App\Models\Role',
68            'description'     => 'update',
69            'causer_id'       => auth('user')->user()->id,
70            'causer_type'     => 'App\Models\User',
71            'properties'      => null,
72        ]);
73
74        return redirect('dashboard/roles')->with('success', 'success');
75    }
76
77    public function destroy($role_id){
78        $role = Role::where('status', '!=', -1)
79                        ->findOrFail($role_id);
80
81        $role->delete();
82
83        $this->ActivityLogsService->insert([
84            'subject_id'      => $role_id,
85            'subject_type'    => 'App\Models\Role',
86            'description'     => 'delete',
87            'causer_id'       => auth('user')->user()->id,
88            'causer_type'     => 'App\Models\User',
89            'properties'      => null,
90        ]);
91
92        return redirect()->back()->with('success', trans('admin.success'));
93    }
94}