1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Testimonials\Http\Controllers\Managerarea; |
6
|
|
|
|
7
|
|
|
use Cortex\Foundation\DataTables\ImportLogsDataTable; |
8
|
|
|
use Cortex\Foundation\Http\Requests\ImportFormRequest; |
9
|
|
|
use Cortex\Foundation\Importers\DefaultImporter; |
10
|
|
|
use Cortex\Testimonials\Models\Testimonial; |
11
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
12
|
|
|
use Cortex\Foundation\DataTables\LogsDataTable; |
13
|
|
|
use Cortex\Foundation\Http\Controllers\AuthorizedController; |
14
|
|
|
use Cortex\Testimonials\DataTables\Managerarea\TestimonialsDataTable; |
15
|
|
|
use Cortex\Testimonials\Http\Requests\Managerarea\TestimonialFormRequest; |
16
|
|
|
|
17
|
|
|
class TestimonialsController extends AuthorizedController |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected $resource = Testimonial::class; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* List all testimonials. |
26
|
|
|
* |
27
|
|
|
* @param \Cortex\Testimonials\DataTables\Managerarea\TestimonialsDataTable $testimonialsDataTable |
28
|
|
|
* |
29
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
30
|
|
|
*/ |
31
|
|
|
public function index(TestimonialsDataTable $testimonialsDataTable) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
return $testimonialsDataTable->with([ |
34
|
|
|
'id' => 'managerarea-testimonials-index-table', |
35
|
|
|
'phrase' => trans('cortex/testimonials::common.testimonials'), |
36
|
|
|
])->render('cortex/foundation::managerarea.pages.datatable'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* List testimonial logs. |
41
|
|
|
* |
42
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
43
|
|
|
* @param \Cortex\Foundation\DataTables\LogsDataTable $logsDataTable |
44
|
|
|
* |
45
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
public function logs(Testimonial $testimonial, LogsDataTable $logsDataTable) |
48
|
|
|
{ |
49
|
|
|
return $logsDataTable->with([ |
50
|
|
|
'resource' => $testimonial, |
51
|
|
|
'tabs' => 'managerarea.testimonials.tabs', |
52
|
|
|
'phrase' => trans('cortex/testimonials::common.testimonials'), |
53
|
|
|
'id' => "managerarea-testimonials-{$testimonial->getKey()}-logs-table", |
54
|
|
|
])->render('cortex/foundation::managerarea.pages.datatable-logs'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Import testimonials. |
59
|
|
|
* |
60
|
|
|
* @return \Illuminate\View\View |
61
|
|
|
*/ |
62
|
|
|
public function import() |
63
|
|
|
{ |
64
|
|
|
return view('cortex/foundation::adminarea.pages.import', [ |
65
|
|
|
'id' => 'adminarea-testimonials-import', |
66
|
|
|
'tabs' => 'adminarea.testimonials.tabs', |
67
|
|
|
'url' => route('adminarea.testimonials.hoard'), |
68
|
|
|
'phrase' => trans('cortex/testimonials::common.testimonials'), |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Hoard testimonials. |
74
|
|
|
* |
75
|
|
|
* @param \Cortex\Foundation\Http\Requests\ImportFormRequest $request |
76
|
|
|
* @param \Cortex\Foundation\Importers\DefaultImporter $importer |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function hoard(ImportFormRequest $request, DefaultImporter $importer) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
// Handle the import |
83
|
|
|
$importer->config['resource'] = $this->resource; |
84
|
|
|
$importer->config['name'] = 'id'; |
85
|
|
|
$importer->handleImport(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* List testimonial import logs. |
90
|
|
|
* |
91
|
|
|
* @param \Cortex\Foundation\DataTables\ImportLogsDataTable $importLogsDatatable |
92
|
|
|
* |
93
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
|
|
|
94
|
|
|
*/ |
95
|
|
|
public function importLogs(ImportLogsDataTable $importLogsDatatable) |
96
|
|
|
{ |
97
|
|
|
return $importLogsDatatable->with([ |
98
|
|
|
'resource' => 'testimonial', |
99
|
|
|
'tabs' => 'adminarea.testimonials.tabs', |
100
|
|
|
'id' => 'adminarea-testimonials-import-logs-table', |
101
|
|
|
'phrase' => trans('cortex/testimonials::common.testimonials'), |
102
|
|
|
])->render('cortex/foundation::adminarea.pages.datatable-import-logs'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Create new testimonial. |
107
|
|
|
* |
108
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
109
|
|
|
* |
110
|
|
|
* @return \Illuminate\View\View |
111
|
|
|
*/ |
112
|
|
|
public function create(Testimonial $testimonial) |
113
|
|
|
{ |
114
|
|
|
return $this->form($testimonial); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Edit given testimonial. |
119
|
|
|
* |
120
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
121
|
|
|
* |
122
|
|
|
* @return \Illuminate\View\View |
123
|
|
|
*/ |
124
|
|
|
public function edit(Testimonial $testimonial) |
125
|
|
|
{ |
126
|
|
|
return $this->form($testimonial); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Show testimonial create/edit form. |
131
|
|
|
* |
132
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
133
|
|
|
* |
134
|
|
|
* @return \Illuminate\View\View |
135
|
|
|
*/ |
136
|
|
|
protected function form(Testimonial $testimonial) |
137
|
|
|
{ |
138
|
|
|
return view('cortex/testimonials::managerarea.pages.testimonial', compact('testimonial')); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Store new testimonial. |
143
|
|
|
* |
144
|
|
|
* @param \Cortex\Testimonials\Http\Requests\Managerarea\TestimonialFormRequest $request |
145
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
146
|
|
|
* |
147
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
148
|
|
|
*/ |
149
|
|
|
public function store(TestimonialFormRequest $request, Testimonial $testimonial) |
150
|
|
|
{ |
151
|
|
|
return $this->process($request, $testimonial); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Update given testimonial. |
156
|
|
|
* |
157
|
|
|
* @param \Cortex\Testimonials\Http\Requests\Managerarea\TestimonialFormRequest $request |
158
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
159
|
|
|
* |
160
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
161
|
|
|
*/ |
162
|
|
|
public function update(TestimonialFormRequest $request, Testimonial $testimonial) |
163
|
|
|
{ |
164
|
|
|
return $this->process($request, $testimonial); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Process stored/updated testimonial. |
169
|
|
|
* |
170
|
|
|
* @param \Illuminate\Foundation\Http\FormRequest $request |
171
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
172
|
|
|
* |
173
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
174
|
|
|
*/ |
175
|
|
|
protected function process(FormRequest $request, Testimonial $testimonial) |
176
|
|
|
{ |
177
|
|
|
// Prepare required input fields |
178
|
|
|
$data = $request->validated(); |
179
|
|
|
|
180
|
|
|
// Save testimonial |
181
|
|
|
$testimonial->fill($data)->save(); |
182
|
|
|
|
183
|
|
|
return intend([ |
184
|
|
|
'url' => route('managerarea.testimonials.index'), |
185
|
|
|
'with' => ['success' => trans('cortex/foundation::messages.resource_saved', ['resource' => 'testimonial', 'id' => $testimonial->getKey()])], |
|
|
|
|
186
|
|
|
]); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Destroy given testimonial. |
191
|
|
|
* |
192
|
|
|
* @param \Cortex\Testimonials\Models\Testimonial $testimonial |
193
|
|
|
* |
194
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
195
|
|
|
*/ |
196
|
|
|
public function destroy(Testimonial $testimonial) |
197
|
|
|
{ |
198
|
|
|
$testimonial->delete(); |
199
|
|
|
|
200
|
|
|
return intend([ |
201
|
|
|
'url' => route('managerarea.testimonials.index'), |
202
|
|
|
'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => 'testimonial', 'id' => $testimonial->getKey()])], |
|
|
|
|
203
|
|
|
]); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.