RoomCrudController::setupListOperation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 21
rs 9.9
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Requests\RoomRequest as StoreRequest;
6
use App\Models\Room;
7
use Backpack\CRUD\app\Http\Controllers\CrudController;
8
use Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
9
use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
10
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
11
use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
12
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
13
14
class RoomCrudController extends CrudController
15
{
16
    use 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\Admin\RoomCrudController: $model, $query, $entity_name_plural
Loading history...
17
    use 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\Admin\RoomCrudController.
Loading history...
18
    use 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\Admin\RoomCrudController: $entity_name, $model
Loading history...
19
    use DeleteOperation;
20
21
    public function setup()
22
    {
23
        CRUD::setModel(Room::class);
24
        CRUD::setRoute(config('backpack.base.route_prefix').'/room');
25
        CRUD::setEntityNameStrings(__('room'), __('rooms'));
26
    }
27
28
    protected function setupListOperation()
29
    {
30
        CRUD::setColumns([
31
            [
32
                // 1-n relationship
33
                'label' => 'Campus',
34
                'type' => 'relationship',
35
                'name' => 'campus',
36
                'attribute' => 'name',
37
            ],
38
39
            [
40
                'name' => 'name',
41
                'label' => 'Name',
42
                'type' => 'text',
43
            ],
44
45
            [
46
                'name' => 'capacity',
47
                'label' => 'Capacity',
48
                'type' => 'number',
49
            ],
50
        ]);
51
    }
52
53
    protected function setupCreateOperation()
54
    {
55
        CRUD::setValidation(StoreRequest::class);
56
        CRUD::addFields([
57
            [
58
                // 1-n relationship
59
                'label' => 'Campus',
60
                'type' => 'select',
61
                'entity' => 'campus',
62
                'name' => 'campus_id',
63
                'attribute' => 'name',
64
            ],
65
66
            [
67
                'name' => 'name',
68
                'label' => 'Name',
69
                'type' => 'text',
70
            ],
71
72
            [
73
                'name' => 'capacity',
74
                'label' => 'Capacity',
75
                'type' => 'number',
76
            ],
77
        ]);
78
    }
79
80
    protected function setupUpdateOperation()
81
    {
82
        $this->setupCreateOperation();
83
    }
84
}
85