Passed
Push — master ( 2db616...058151 )
by Thomas
07:55 queued 12s
created

ScheduledPaymentCrudController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 51
c 1
b 0
f 0
dl 0
loc 122
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setupListOperation() 0 60 2
A setupCreateOperation() 0 6 1
A setup() 0 6 1
A setupUpdateOperation() 0 3 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Requests\ScheduledPaymentRequest;
6
use App\Models\Invoice;
7
use App\Models\Paymentmethod;
8
use App\Models\ScheduledPayment;
9
use App\Models\Teacher;
10
use Backpack\CRUD\app\Http\Controllers\CrudController;
11
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
12
13
/**
14
 * Class ScheduledPaymentCrudController
15
 * @package App\Http\Controllers\Admin
16
 * @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
17
 */
18
class ScheduledPaymentCrudController extends CrudController
19
{
20
    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...edPaymentCrudController: $model, $query, $entity_name_plural
Loading history...
21
    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...edPaymentCrudController: $entity_name, $model
Loading history...
22
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
23
24
    /**
25
     * Configure the CrudPanel object. Apply settings to all operations.
26
     *
27
     * @return void
28
     */
29
    public function setup()
30
    {
31
        CRUD::setModel(\App\Models\ScheduledPayment::class);
32
        CRUD::setRoute(config('backpack.base.route_prefix') . '/scheduled-payment');
33
        CRUD::setEntityNameStrings(__('scheduled payment'), __('scheduled payments'));
34
        CRUD::enableExportButtons();
35
    }
36
37
    /**
38
     * Define what happens when the List operation is loaded.
39
     *
40
     * @see  https://backpackforlaravel.com/docs/crud-operation-list-entries
41
     * @return void
42
     */
43
    protected function setupListOperation()
44
    {
45
        CRUD::addColumn([
46
            'name' => 'enrollment.student',
47
            'key'       => 'student_lastname',
48
            'attribute' => 'lastname',
49
            'label' => __('Last Name'),
50
            'type' => 'relationship',
51
            'searchLogic' => function ($query, $column, $searchTerm) {
52
                $query->orWhereHas('enrollment', function ($q) use ($searchTerm) {
53
                    $q->whereHas('user', function ($q) use ($searchTerm) {
54
                        $q->where('lastname', 'like', '%'.$searchTerm.'%');
55
                    });
56
                });
57
            },
58
        ]);
59
60
        CRUD::addColumn([
61
            'name' => 'enrollment.student',
62
            'key'       => 'student_firstname',
63
            'attribute' => 'firstname',
64
            'label' => __('First Name'),
65
            'type' => 'relationship',
66
            'searchLogic' => function ($query, $column, $searchTerm) {
67
                $query->orWhereHas('enrollment', function ($q) use ($searchTerm) {
68
                    $q->whereHas('user', function ($q) use ($searchTerm) {
69
                        $q->where('firstname', 'like', '%'.$searchTerm.'%');
70
                    });
71
                });
72
            },
73
        ]);
74
75
76
        CRUD::addColumn([
77
            'name' => 'enrollment.student',
78
            'key'       => 'student_email',
79
            'attribute' => 'email',
80
            'label' => __('Email'),
81
            'type' => 'relationship',
82
            'searchLogic' => function ($query, $column, $searchTerm) {
83
                $query->orWhereHas('enrollment', function ($q) use ($searchTerm) {
84
                    $q->whereHas('user', function ($q) use ($searchTerm) {
85
                        $q->where('email', 'like', '%'.$searchTerm.'%');
86
                    });
87
                });
88
            },
89
        ]);
90
91
        if (config('app.currency_position') === 'before') {
92
            $currency = array('prefix' => config('app.currency_symbol'));
93
        } else {
94
            $currency = array('suffix' => config('app.currency_symbol'));
95
        }
96
97
        CRUD::addColumn(array_merge([
98
            'name'  => 'value',
99
            'label' => __('Value'),
100
            'type'  => 'number'], $currency));
101
102
        CRUD::column('date');
103
104
        /**
105
         * Columns can be defined using the fluent syntax or array syntax:
106
         * - CRUD::column('price')->type('number');
107
         * - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
108
         */
109
    }
110
111
    /**
112
     * Define what happens when the Create operation is loaded.
113
     *
114
     * @see https://backpackforlaravel.com/docs/crud-operation-create
115
     * @return void
116
     */
117
    protected function setupCreateOperation()
118
    {
119
        CRUD::setValidation(ScheduledPaymentRequest::class);
120
121
        CRUD::field('value');
122
        CRUD::field('date');
123
124
        /**
125
         * Fields can be defined using the fluent syntax or array syntax:
126
         * - CRUD::field('price')->type('number');
127
         * - CRUD::addField(['name' => 'price', 'type' => 'number']));
128
         */
129
    }
130
131
    /**
132
     * Define what happens when the Update operation is loaded.
133
     *
134
     * @see https://backpackforlaravel.com/docs/crud-operation-update
135
     * @return void
136
     */
137
    protected function setupUpdateOperation()
138
    {
139
        $this->setupCreateOperation();
140
    }
141
}
142