Cancelled
Push — test-branch ( 5c534a )
by Yonathan
06:17 queued 06:17
created

UserCrudController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 50
dl 0
loc 85
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 63 1
A update() 0 4 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use App\Models\UserRole;
7
8
class UserCrudController extends CrudController
9
{
10
    /**
11
     * Prepare the admin interface by setting the associated
12
     * model, setting the route, and adding custom columns/fields.
13
     *
14
     * @return void
15
     */
16
    public function setup() : void
17
    {
18
        $this->crud->setModel("App\Models\User");
19
        $this->crud->setRoute("admin/user");
20
        $this->crud->setEntityNameStrings('user', 'users');
21
22
        $this->crud->denyAccess('create');
23
        $this->crud->denyAccess('delete');
24
25
        // Add the custom blade button found in resources/views/vendor/backpack/crud/buttons/profile_edit.blade.php
26
        $this->crud->addButtonFromView('line', 'profile_edit', 'profile_edit', 'end');
27
28
        $this->crud->addColumn([
29
            'name' => 'name',
30
            'type' => 'text',
31
            'label' => 'Name'
32
        ]);
33
        $this->crud->addColumn([
34
            'name' => 'email',
35
            'type' => 'text',
36
            'label' => 'Email'
37
        ]);
38
        $this->crud->addColumn([
39
            'name' => 'user_role.name',
40
            'type' => 'text',
41
            'label' => 'Role'
42
        ]);
43
        $this->crud->addColumn([
44
            'name' => 'is_priority',
45
            'type' => 'check',
46
            'label' => 'Priority'
47
        ]);
48
49
        $this->crud->addFilter([
50
            'name' => 'user_role',
51
            'type' => 'select2',
52
            'label' => 'Role'
53
        ], function () {
54
            return UserRole::all()->keyBy('id')->pluck('name', 'id')->toArray();
55
        }, function ($value) : void {
56
            $this->crud->addClause('where', 'user_role_id', $value);
57
        });
58
59
        $this->crud->addField([
60
            'name' => 'name',
61
            'label' => "Name",
62
            'type' => 'text',
63
            'attributes' => [
64
                'readonly'=>'readonly'
65
            ]
66
        ]);
67
        $this->crud->addField([
68
            'label' => "Role",
69
            'type' => 'select',
70
            'name' => 'user_role_id', // the db column for the foreign key
71
            'entity' => 'user_role', // the method that defines the relationship in your Model
72
            'attribute' => 'name', // foreign key attribute that is shown to user
73
            'model' => "App\Models\UserRole" // foreign key model
74
        ]);
75
        $this->crud->addField([
76
            'name' => 'is_priority',
77
            'type' => 'checkbox',
78
            'label' => 'Priority'
79
        ]);
80
    }
81
82
    /**
83
     * Action for updating an existing User in the database.
84
     *
85
     * @param \Illuminate\Http\Request $request Incoming form request.
86
     *
87
     * @return \Illuminate\Http\RedirectResponse
88
     */
89
    public function update($request) // phpcs:ignore
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
    public function update(/** @scrutinizer ignore-unused */ $request) // phpcs:ignore

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
    {
91
        $response = parent::updateCrud();
92
        return $response;
93
    }
94
}
95