Passed
Push — feature/user-softdeletes ( e1960a )
by Grant
32:06 queued 16:57
created

UserCrudController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Models\UserRole;
6
use Backpack\CRUD\app\Http\Controllers\CrudController;
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 1
    public function setup() : void
17
    {
18 1
        $this->crud->setModel('App\Models\User');
19 1
        $this->crud->setRoute('admin/user');
20 1
        $this->crud->setEntityNameStrings('user', 'users');
21
22 1
        $this->crud->denyAccess('create');
23
24 1
        $this->crud->addColumn([
25 1
            'name' => 'name',
26
            'type' => 'text',
27
            'label' => 'Name'
28
        ]);
29 1
        $this->crud->addColumn([
30 1
            'name' => 'email',
31
            'type' => 'text',
32
            'label' => 'Email'
33
        ]);
34 1
        $this->crud->addColumn([
35 1
            'name' => 'user_role.name',
36
            'type' => 'text',
37
            'label' => 'Role'
38
        ]);
39 1
        $this->crud->addColumn([
40 1
            'name' => 'is_priority',
41
            'type' => 'check',
42
            'label' => 'Priority'
43
        ]);
44
45 1
        $this->crud->addFilter([
46 1
            'name' => 'user_role',
47
            'type' => 'select2',
48
            'label' => 'Role'
49
        ], function () {
50 1
            return UserRole::all()->keyBy('id')->pluck('name', 'id')->toArray();
51
        }, function ($value) : void {
52
            $this->crud->addClause('where', 'user_role_id', $value);
53 1
        });
54
55 1
        $this->crud->addField([
56 1
            'name' => 'name',
57
            'label' => 'Name',
58
            'type' => 'text',
59
            'attributes' => [
60
                'readonly'=>'readonly'
61
            ]
62
        ]);
63 1
        $this->crud->addField([
64 1
            'label' => 'Role',
65
            'type' => 'select',
66
            'name' => 'user_role_id', // The db column for the foreign key.
67
            'entity' => 'user_role', // The method that defines the relationship in your Model.
68
            'attribute' => 'name', // Foreign key attribute that is shown to user.
69
            'model' => 'App\Models\UserRole' // Foreign key model.
70
        ]);
71 1
        $this->crud->addField([
72 1
            'name' => 'is_priority',
73
            'type' => 'checkbox',
74
            'label' => 'Priority'
75
        ]);
76 1
    }
77
78
    /**
79
     * Action for updating an existing User in the database.
80
     *
81
     * @param \Illuminate\Http\Request $request Incoming form request.
82
     *
83
     * @return \Illuminate\Http\RedirectResponse
84
     */
85
    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

85
    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...
86
    {
87
        $response = parent::updateCrud();
88
89
        return $response;
90
    }
91
}
92