|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Room; |
|
6
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
|
|
9
|
|
|
class RoomController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
private function getRouteName() |
|
12
|
|
|
{ |
|
13
|
|
|
return 'room'; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function index() |
|
17
|
|
|
{ |
|
18
|
|
|
$title = trans('general.rooms'); |
|
19
|
|
|
|
|
20
|
|
|
$dataset = Room::select('id', 'number', 'floor', 'capacity', 'price') |
|
21
|
|
|
->paginate($this->getItemsPerPage()); |
|
22
|
|
|
|
|
23
|
|
|
$view_data = [ |
|
24
|
|
|
'columns' => $this->getColumns(), |
|
25
|
|
|
'dataset' => $dataset, |
|
26
|
|
|
'route_name' => $this->getRouteName(), |
|
27
|
|
|
'title' => $title, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
return view('list', $view_data); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function store(/*RoomRequest $request*/ Request $request, $id = null) |
|
34
|
|
|
{ |
|
35
|
|
|
if($id === null) { |
|
36
|
|
|
$object = new Room(); |
|
37
|
|
|
} else { |
|
38
|
|
|
try { |
|
39
|
|
|
$object = Room::findOrFail($id); |
|
40
|
|
|
} catch (ModelNotFoundException $e) { |
|
41
|
|
|
return Controller::returnBack([ |
|
42
|
|
|
'message' => trans('general.object_not_found'), |
|
43
|
|
|
'alert-class' => 'alert-danger' |
|
44
|
|
|
]); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$object->fill($request->all()); |
|
49
|
|
|
$object->save(); |
|
50
|
|
|
|
|
51
|
|
|
return redirect()->route($this->getRouteName() . '.index') |
|
52
|
|
|
->with([ |
|
53
|
|
|
'message' => trans('general.saved'), |
|
54
|
|
|
'alert-class' => 'alert-success' |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function delete($id) |
|
59
|
|
|
{ |
|
60
|
|
|
Room::destroy($id); |
|
61
|
|
|
|
|
62
|
|
|
$data = ['class' => 'alert-success', 'message' => trans('general.deleted')]; |
|
63
|
|
|
|
|
64
|
|
|
return response()->json($data); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function showAddEditForm($id = null) |
|
68
|
|
|
{ |
|
69
|
|
|
if ($id === null) { |
|
70
|
|
|
$dataset = new Room(); |
|
71
|
|
|
$title = trans('general.add'); |
|
72
|
|
|
$submit_route = route($this->getRouteName().'.postadd'); |
|
73
|
|
|
} else { |
|
74
|
|
|
try { |
|
75
|
|
|
$dataset = Room::findOrFail($id); |
|
76
|
|
|
} catch (ModelNotFoundException $e) { |
|
77
|
|
|
return Controller::returnBack([ |
|
78
|
|
|
'message' => trans('general.object_not_found'), |
|
79
|
|
|
'alert-class' => 'alert-danger', |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$title = trans('general.edit'); |
|
84
|
|
|
$submit_route = route($this->getRouteName().'.postedit', $id); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$title .= ' '.mb_strtolower(trans('general.room')); |
|
88
|
|
|
|
|
89
|
|
|
$view_data = [ |
|
90
|
|
|
'dataset' => $dataset, |
|
91
|
|
|
'fields' => $this->getFields(), |
|
92
|
|
|
'title' => $title, |
|
93
|
|
|
'submit_route' => $submit_route, |
|
94
|
|
|
'route_name' => $this->getRouteName(), |
|
95
|
|
|
]; |
|
96
|
|
|
|
|
97
|
|
|
return view('addedit', $view_data); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
private function getFields() |
|
101
|
|
|
{ |
|
102
|
|
|
return [ |
|
103
|
|
|
[ |
|
104
|
|
|
'id' => 'number', |
|
105
|
|
|
'title' => trans('general.number'), |
|
106
|
|
|
'value' => function (Room $data) { |
|
107
|
|
|
return $data->number; |
|
108
|
|
|
}, |
|
109
|
|
|
'type' => 'number', |
|
110
|
|
|
'optional' => [ |
|
111
|
|
|
'required' => 'required', |
|
112
|
|
|
], |
|
113
|
|
|
], |
|
114
|
|
|
[ |
|
115
|
|
|
'id' => 'floor', |
|
116
|
|
|
'title' => trans('general.floor'), |
|
117
|
|
|
'value' => function (Room $data) { |
|
118
|
|
|
return $data->floor; |
|
119
|
|
|
}, |
|
120
|
|
|
'type' => 'number', |
|
121
|
|
|
'optional' => [ |
|
122
|
|
|
'required' => 'required', |
|
123
|
|
|
], |
|
124
|
|
|
], |
|
125
|
|
|
[ |
|
126
|
|
|
'id' => 'capacity', |
|
127
|
|
|
'title' => trans('general.capacity'), |
|
128
|
|
|
'value' => function (Room $data) { |
|
129
|
|
|
return $data->capacity; |
|
130
|
|
|
}, |
|
131
|
|
|
'type' => 'number', |
|
132
|
|
|
'optional' => [ |
|
133
|
|
|
'required' => 'required', |
|
134
|
|
|
], |
|
135
|
|
|
], |
|
136
|
|
|
[ |
|
137
|
|
|
'id' => 'price', |
|
138
|
|
|
'title' => trans('general.price'), |
|
139
|
|
|
'value' => function (Room $data) { |
|
140
|
|
|
return $data->price; |
|
141
|
|
|
}, |
|
142
|
|
|
'type' => 'number', |
|
143
|
|
|
'optional' => [ |
|
144
|
|
|
'step' => '0.01', |
|
145
|
|
|
'placeholder' => '0.00', |
|
146
|
|
|
'required' => 'required', |
|
147
|
|
|
], |
|
148
|
|
|
], |
|
149
|
|
|
[ |
|
150
|
|
|
'id' => 'comments', |
|
151
|
|
|
'title' => trans('general.comments'), |
|
152
|
|
|
'value' => function (Room $data) { |
|
153
|
|
|
return $data->comments; |
|
154
|
|
|
}, |
|
155
|
|
|
'type' => 'textarea', |
|
156
|
|
|
], |
|
157
|
|
|
]; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
private function getColumns() |
|
161
|
|
|
{ |
|
162
|
|
|
$dataset = [ |
|
163
|
|
|
[ |
|
164
|
|
|
'title' => trans('general.number'), |
|
165
|
|
|
'value' => function (Room $data) { |
|
166
|
|
|
return $data->number; |
|
167
|
|
|
}, |
|
168
|
|
|
], |
|
169
|
|
|
[ |
|
170
|
|
|
'title' => trans('general.floor'), |
|
171
|
|
|
'value' => function (Room $data) { |
|
172
|
|
|
return $data->floor; |
|
173
|
|
|
}, |
|
174
|
|
|
], |
|
175
|
|
|
[ |
|
176
|
|
|
'title' => trans('general.capacity'), |
|
177
|
|
|
'value' => function (Room $data) { |
|
178
|
|
|
return $data->capacity; |
|
179
|
|
|
}, |
|
180
|
|
|
], |
|
181
|
|
|
[ |
|
182
|
|
|
'title' => trans('general.price'), |
|
183
|
|
|
'value' => function (Room $data) { |
|
184
|
|
|
return $data->price; |
|
185
|
|
|
}, |
|
186
|
|
|
], |
|
187
|
|
|
]; |
|
188
|
|
|
|
|
189
|
|
|
return $dataset; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|