DiscountCrudController::setupListOperation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 19
rs 9.9332
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Requests\DiscountRequest as StoreRequest;
6
use App\Models\Discount;
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 DiscountCrudController 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\DiscountCrudController: $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\DiscountCrudController.
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\DiscountCrudController: $entity_name, $model
Loading history...
19
    use DeleteOperation;
20
21
    public function setup()
22
    {
23
        /*
24
        |--------------------------------------------------------------------------
25
        | CrudPanel Basic Information
26
        |--------------------------------------------------------------------------
27
        */
28
        CRUD::setModel(Discount::class);
29
        CRUD::setRoute(config('backpack.base.route_prefix').'/discount');
30
        CRUD::setEntityNameStrings(__('discount'), __('discounts'));
31
    }
32
33
    protected function setupListOperation()
34
    {
35
        CRUD::setColumns([
36
            [
37
                'name' => 'id',
38
                'label' => 'ID',
39
            ],
40
            [
41
                // Discount name
42
                'label' => __('Name'),
43
                'type' => 'text',
44
                'name' => 'name',
45
            ],
46
            [
47
                // Value
48
                'label' => __('Discount Value'),
49
                'type' => 'decimal',
50
                'name' => 'value',
51
                'suffix' => '%',
52
            ],
53
        ]);
54
    }
55
56
    protected function setupCreateOperation()
57
    {
58
        CRUD::setValidation(StoreRequest::class);
59
        CRUD::addFields([
60
            [
61
                // Discount name
62
                'label' => __('Name'),
63
                'type' => 'text',
64
                'name' => 'name',
65
            ],
66
            [
67
                // Value
68
                'label' => __('Discount Value (0-100%)'),
69
                'type' => 'number',
70
                'attributes' => ['step' => '1'],
71
                'name' => 'value',
72
            ],
73
        ]);
74
    }
75
76
    protected function setupUpdateOperation()
77
    {
78
        $this->setupCreateOperation();
79
    }
80
}
81