Passed
Pull Request — release/1.0.15 (#1655)
by Tristan
10:06 queued 02:47
created

DepartmentCrudController::setupListOperation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 42
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 42
rs 9.488
cc 2
nc 2
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
// Validation.
6
use App\Http\Requests\DepartmentCrudRequest as StoreRequest;
7
use App\Http\Requests\DepartmentCrudRequest as UpdateRequest;
8
use Backpack\CRUD\app\Http\Controllers\CrudController;
9
use Illuminate\Support\Facades\App;
10
11
class DepartmentCrudController extends CrudController
12
{
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...perations\ListOperation requires some properties which are not provided by App\Http\Controllers\Adm...epartmentCrudController: $model, $query, $entity_name_plural
Loading history...
14
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
0 ignored issues
show
Bug introduced by
The trait Backpack\CRUD\app\Http\C...rations\CreateOperation requires the property $entity_name which is not provided by App\Http\Controllers\Adm...epartmentCrudController.
Loading history...
15
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...rations\UpdateOperation requires some properties which are not provided by App\Http\Controllers\Adm...epartmentCrudController: $model, $entity_name
Loading history...
16
17
    /**
18
     * Prepare the admin interface by setting the associated
19
     * model, setting the route, and adding custom columns/fields.
20
     *
21
     * @return void
22
     */
23
    public function setup() : void
24
    {
25
        // Eloquent model to associate with this collection of views and controller actions.
26
        $this->crud->setModel('App\Models\Lookup\Department');
27
        // Custom backpack route.
28
        $this->crud->setRoute('admin/department');
29
        // Custom strings to display within the backpack UI.
30
        $this->crud->setEntityNameStrings('department', 'departments');
31
32
        $this->crud->operation(['create', 'update'], function () {
33
            $this->crud->addField([
34
                'name' => 'name',
35
                'type' => 'text',
36
                'label' => 'Name',
37
            ]);
38
39
            $this->crud->addField([
40
                'name' => 'impact',
41
                'type' => 'textarea',
42
                'label' => 'Impact',
43
            ]);
44
45
            $this->crud->addField([
46
                'name' => 'preference',
47
                'type' => 'textarea',
48
                'label' => 'Preference',
49
            ]);
50
        });
51
    }
52
53
    public function setupListOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupListOperation()
Loading history...
54
    {
55
        // Required for order logic.
56
        $locale = 'en';
57
        if (null !== $this->request->input('locale')) {
58
            $locale = $this->request->input('locale');
59
        }
60
        App::setLocale($locale);
61
62
        // Remove delete button.
63
        $this->crud->removeButton('delete');
64
65
        // Add custom columns to the Department index view.
66
        $this->crud->addColumn([
67
            'name' => 'id',
68
            'type' => 'text',
69
            'label' => 'ID',
70
            'orderable' => true,
71
        ]);
72
73
        $this->crud->addColumn([
74
            'name' => 'name',
75
            'type' => 'text',
76
            'label' => 'Name',
77
            'orderable' => true,
78
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
79
                return $query->orderBy('name->' . $locale, $columnDirection)->select('*');
80
            }
81
        ]);
82
83
        $this->crud->addColumn([
84
            'name' => 'impact',
85
            'type' => 'text',
86
            'label' => 'Impact',
87
            'orderable' => false,
88
        ]);
89
90
        $this->crud->addColumn([
91
            'name' => 'preference',
92
            'type' => 'text',
93
            'label' => 'Preference',
94
            'orderable' => false,
95
        ]);
96
    }
97
98
    public function setupCreateOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupCreateOperation()
Loading history...
99
    {
100
        $this->crud->setValidation(StoreRequest::class);
101
    }
102
103
    public function setupUpdateOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupUpdateOperation()
Loading history...
104
    {
105
        $this->crud->setValidation(UpdateRequest::class);
106
    }
107
}
108