1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
6
|
|
|
use Backpack\CRUD\app\Http\Requests\MenuRequest; |
7
|
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MenuCrudController. |
11
|
|
|
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud |
12
|
|
|
*/ |
13
|
|
|
class MenuCrudController extends CrudController |
14
|
|
|
{ |
15
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
16
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; |
17
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
18
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; |
19
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Configure the CrudPanel object. Apply settings to all operations. |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function setup() |
27
|
|
|
{ |
28
|
|
|
$this->crud->setModel(\Backpack\CRUD\app\Models\Menu::class); |
29
|
|
|
$this->crud->setRoute(config('backpack.base.route_prefix').'/menu'); |
30
|
|
|
$this->crud->setEntityNameStrings('menu', 'menus'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Define what happens when the List operation is loaded. |
35
|
|
|
* |
36
|
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
protected function setupListOperation() |
40
|
|
|
{ |
41
|
|
|
$this->setupColumns(false); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Columns can be defined using the fluent syntax or array syntax: |
45
|
|
|
* - $this->crud->column('price')->type('number'); |
46
|
|
|
* - $this->crud->addColumn(['name' => 'price', 'type' => 'number']);. |
47
|
|
|
*/ |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function setupShowOperation() |
51
|
|
|
{ |
52
|
|
|
$this->crud->set('show.setFromDb', false); |
53
|
|
|
$this->setupColumns(true); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Define what happens when the Create operation is loaded. |
58
|
|
|
* |
59
|
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-create |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
protected function setupCreateOperation() |
63
|
|
|
{ |
64
|
|
|
$this->crud->setValidation(MenuRequest::class); |
65
|
|
|
|
66
|
|
|
$this->setupFields(); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Fields can be defined using the fluent syntax or array syntax: |
70
|
|
|
* - $this->crud->field('price')->type('number'); |
71
|
|
|
* - $this->crud->addField(['name' => 'price', 'type' => 'number']));. |
72
|
|
|
*/ |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Define what happens when the Update operation is loaded. |
77
|
|
|
* |
78
|
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-update |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
protected function setupUpdateOperation() |
82
|
|
|
{ |
83
|
|
|
$this->setupCreateOperation(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function setupColumns($isShowing = false) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$this->crud->addButtonFromModelFunction('line', 'custom_actions', 'customActions', 'beginning'); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$this->crud->addColumn([ |
91
|
|
|
'name' => 'name', |
92
|
|
|
'label' => 'Name', |
93
|
|
|
'type' => 'text', |
94
|
|
|
]); |
95
|
|
|
$this->crud->addColumn([ |
96
|
|
|
'name' => 'placement', |
97
|
|
|
'label' => 'Placement', |
98
|
|
|
'type' => 'select_from_array', |
99
|
|
|
'options' => config('backpack.menu.placement'), |
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private function setupFields() |
104
|
|
|
{ |
105
|
|
|
$this->crud->addField([ |
106
|
|
|
'name' => 'name', |
107
|
|
|
'label' => 'Name', |
108
|
|
|
'type' => 'text', |
109
|
|
|
]); |
110
|
|
|
$this->crud->addField([ |
111
|
|
|
'name' => 'placement', |
112
|
|
|
'label' => 'Placement', |
113
|
|
|
'type' => 'select2_from_array', |
114
|
|
|
'options' => config('backpack.menu.placement'), |
115
|
|
|
'allows_null' => true, |
116
|
|
|
'default' => null, |
117
|
|
|
]); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.