Passed
Push — bugfix/manager-not-created-aft... ( 758290...8fadf0 )
by Chris
10:55
created

UserCrudController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

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