Completed
Push — master ( d0984d...8e3192 )
by Jeremy
10:29 queued 05:27
created

LaravelRolesApiController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 12 1
A index() 0 10 1
1
<?php
2
3
namespace jeremykenedy\LaravelRoles\App\Http\Controllers\Api;
4
5
use App\Http\Controllers\Controller;
6
use jeremykenedy\LaravelRoles\App\Http\Requests\StoreRoleRequest;
7
use jeremykenedy\LaravelRoles\Traits\RolesAndPermissionsHelpersTrait;
8
use jeremykenedy\LaravelRoles\Traits\RolesUsageAuthTrait;
9
10
class LaravelRolesApiController extends Controller
11
{
12
    use RolesAndPermissionsHelpersTrait;
0 ignored issues
show
introduced by
The trait jeremykenedy\LaravelRole...PermissionsHelpersTrait requires some properties which are not provided by jeremykenedy\LaravelRole...ravelRolesApiController: $role_id, $user_id, $id, $roles, $permission_id
Loading history...
13
    // use RolesUsageAuthTrait;
14
15
    /**
16
     * Return all the roles, Permissions, and Users data.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index()
21
    {
22
        $data = $this->getDashboardData();
23
24
        return response()->json([
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(...=> $data['data']), 200) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
25
            'code'      => 200,
26
            'status'    => 'success',
27
            'message'   => 'Success returning all roles and permissions data.',
28
            'data'      => $data['data'],
29
        ], 200);
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return \Illuminate\Http\Response
36
     */
37
    public function store(StoreRoleRequest $request)
38
    {
39
        $roleData = $request->roleFillData();
40
        $rolePermissions = $request->get('permissions');
41
        $role = $this->storeRoleWithPermissions($roleData, $rolePermissions);
42
43
        return response()->json([
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(... 'role' => $role), 201) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
44
            'code'      => 201,
45
            'status'    => 'created',
46
            'message'   => 'Success created new role.',
47
            'role'      => $role,
48
        ], 201);
49
    }
50
}
51