Passed
Push — feature/hr-admin-panel ( cd39be )
by Grant
06:22 queued 10s
created

HrAdvisorCrudController::setupUpdateOperation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 17
rs 9.8333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Models\Lookup\Department;
6
use Backpack\CRUD\app\Http\Controllers\CrudController;
7
8
class HrAdvisorCrudController extends CrudController
9
{
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
11
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
12
13
    /**
14
     * Prepare the admin interface by setting the associated
15
     * model, setting the route, and adding custom columns/fields.
16
     *
17
     * @return void
18
     */
19
    public function setup() : void
20
    {
21
        $this->crud->setModel('App\Models\HrAdvisor');
22
        $this->crud->setRoute('admin/hr');
23
        $this->crud->setEntityNameStrings('HR advisor', 'HR advisors');
24
    }
25
26
    public function setupListOperation()
27
    {
28
        $this->crud->addColumn([
29
            'name' => 'id',
30
            'type' => 'number',
31
            'label' => 'ID'
32
        ]);
33
        $this->crud->addColumn([
34
            'name' => 'user.full_name',
35
            'key' => 'full_name',
36
            'type' => 'text',
37
            'label' => 'Name'
38
        ]);
39
        $this->crud->addColumn([
40
            'name' => 'department.name',
41
            'type' => 'text',
42
            'label' => 'Department',
43
            'limit' => 70
44
        ]);
45
    }
46
47
    public function setupUpdateOperation()
48
    {
49
        $this->crud->addField([
50
            'name' => 'name',
51
            'label' => 'Name',
52
            'type' => 'text',
53
            'attributes' => [
54
                'readonly'=>'readonly'
55
            ]
56
        ]);
57
        $this->crud->addField([
58
            'label' => 'Department',
59
            'type' => 'select2',
60
            'name' => 'department_id', // The db column for the foreign key.
61
            'entity' => 'department', // The method that defines the relationship in your Model.
62
            'attribute' => 'name', // Foreign key attribute that is shown to user.
63
            'model' => 'App\Models\Lookup\Department' // Foreign key model.
64
        ]);
65
    }
66
}
67