This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Cortex\Categories\Http\Controllers\Adminarea; |
||
6 | |||
7 | use Exception; |
||
8 | use Cortex\Categories\Models\Category; |
||
9 | use Illuminate\Foundation\Http\FormRequest; |
||
10 | use Cortex\Foundation\DataTables\LogsDataTable; |
||
11 | use Cortex\Foundation\Importers\DefaultImporter; |
||
12 | use Cortex\Foundation\DataTables\ImportLogsDataTable; |
||
13 | use Cortex\Foundation\Http\Requests\ImportFormRequest; |
||
14 | use Cortex\Foundation\DataTables\ImportRecordsDataTable; |
||
15 | use Cortex\Foundation\Http\Controllers\AuthorizedController; |
||
16 | use Cortex\Categories\DataTables\Adminarea\CategoriesDataTable; |
||
17 | use Cortex\Categories\Http\Requests\Adminarea\CategoryFormRequest; |
||
18 | |||
19 | class CategoriesController extends AuthorizedController |
||
20 | { |
||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | protected $resource = Category::class; |
||
25 | |||
26 | /** |
||
27 | * List all categories. |
||
28 | * |
||
29 | * @param \Cortex\Categories\DataTables\Adminarea\CategoriesDataTable $categoriesDataTable |
||
30 | * |
||
31 | * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
||
32 | */ |
||
33 | public function index(CategoriesDataTable $categoriesDataTable) |
||
34 | { |
||
35 | return $categoriesDataTable->with([ |
||
36 | 'id' => 'adminarea-categories-index-table', |
||
37 | ])->render('cortex/foundation::adminarea.pages.datatable-index'); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * List category logs. |
||
42 | * |
||
43 | * @param \Cortex\Categories\Models\Category $category |
||
44 | * @param \Cortex\Foundation\DataTables\LogsDataTable $logsDataTable |
||
45 | * |
||
46 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
||
0 ignored issues
–
show
|
|||
47 | */ |
||
48 | public function logs(Category $category, LogsDataTable $logsDataTable) |
||
49 | { |
||
50 | return $logsDataTable->with([ |
||
51 | 'resource' => $category, |
||
52 | 'tabs' => 'adminarea.categories.tabs', |
||
53 | 'id' => "adminarea-categories-{$category->getRouteKey()}-logs-table", |
||
54 | ])->render('cortex/foundation::adminarea.pages.datatable-tab'); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Import categories. |
||
59 | * |
||
60 | * @param \Cortex\Categories\Models\Category $category |
||
61 | * @param \Cortex\Foundation\DataTables\ImportRecordsDataTable $importRecordsDataTable |
||
62 | * |
||
63 | * @return \Illuminate\View\View |
||
64 | */ |
||
65 | public function import(Category $category, ImportRecordsDataTable $importRecordsDataTable) |
||
66 | { |
||
67 | return $importRecordsDataTable->with([ |
||
68 | 'resource' => $category, |
||
69 | 'tabs' => 'adminarea.categories.tabs', |
||
70 | 'url' => route('adminarea.categories.stash'), |
||
71 | 'id' => "adminarea-categories-{$category->getRouteKey()}-import-table", |
||
72 | ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Stash categories. |
||
77 | * |
||
78 | * @param \Cortex\Foundation\Http\Requests\ImportFormRequest $request |
||
79 | * @param \Cortex\Foundation\Importers\DefaultImporter $importer |
||
80 | * |
||
81 | * @return void |
||
82 | */ |
||
83 | public function stash(ImportFormRequest $request, DefaultImporter $importer) |
||
0 ignored issues
–
show
|
|||
84 | { |
||
85 | // Handle the import |
||
86 | $importer->config['resource'] = $this->resource; |
||
87 | $importer->handleImport(); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Hoard categories. |
||
92 | * |
||
93 | * @param \Cortex\Foundation\Http\Requests\ImportFormRequest $request |
||
94 | * |
||
95 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
||
96 | */ |
||
97 | public function hoard(ImportFormRequest $request) |
||
98 | { |
||
99 | foreach ((array) $request->get('selected_ids') as $recordId) { |
||
100 | $record = app('cortex.foundation.import_record')->find($recordId); |
||
101 | |||
102 | try { |
||
103 | $fillable = collect($record['data'])->intersectByKeys(array_flip(app('rinvex.categories.category')->getFillable()))->toArray(); |
||
104 | |||
105 | tap(app('rinvex.categories.category')->firstOrNew($fillable), function ($instance) use ($record) { |
||
106 | $instance->save() && $record->delete(); |
||
107 | }); |
||
108 | } catch (Exception $exception) { |
||
109 | $record->notes = $exception->getMessage().(method_exists($exception, 'getMessageBag') ? "\n".json_encode($exception->getMessageBag())."\n\n" : ''); |
||
0 ignored issues
–
show
|
|||
110 | $record->status = 'fail'; |
||
111 | $record->save(); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | return intend([ |
||
116 | 'back' => true, |
||
117 | 'with' => ['success' => trans('cortex/foundation::messages.import_complete')], |
||
118 | ]); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * List category import logs. |
||
123 | * |
||
124 | * @param \Cortex\Foundation\DataTables\ImportLogsDataTable $importLogsDatatable |
||
125 | * |
||
126 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
||
0 ignored issues
–
show
|
|||
127 | */ |
||
128 | public function importLogs(ImportLogsDataTable $importLogsDatatable) |
||
129 | { |
||
130 | return $importLogsDatatable->with([ |
||
131 | 'resource' => trans('cortex/categories::common.category'), |
||
132 | 'tabs' => 'adminarea.categories.tabs', |
||
133 | 'id' => 'adminarea-categories-import-logs-table', |
||
134 | ])->render('cortex/foundation::adminarea.pages.datatable-tab'); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Show category create/edit form. |
||
139 | * |
||
140 | * @param \Cortex\Categories\Models\Category $category |
||
141 | * |
||
142 | * @return \Illuminate\View\View |
||
143 | */ |
||
144 | protected function form(Category $category) |
||
145 | { |
||
146 | return view('cortex/categories::adminarea.pages.category', compact('category')); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Store new category. |
||
151 | * |
||
152 | * @param \Cortex\Categories\Http\Requests\Adminarea\CategoryFormRequest $request |
||
153 | * @param \Cortex\Categories\Models\Category $category |
||
154 | * |
||
155 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
||
156 | */ |
||
157 | public function store(CategoryFormRequest $request, Category $category) |
||
158 | { |
||
159 | return $this->process($request, $category); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * Update given category. |
||
164 | * |
||
165 | * @param \Cortex\Categories\Http\Requests\Adminarea\CategoryFormRequest $request |
||
166 | * @param \Cortex\Categories\Models\Category $category |
||
167 | * |
||
168 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
||
169 | */ |
||
170 | public function update(CategoryFormRequest $request, Category $category) |
||
171 | { |
||
172 | return $this->process($request, $category); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Process stored/updated category. |
||
177 | * |
||
178 | * @param \Illuminate\Foundation\Http\FormRequest $request |
||
179 | * @param \Cortex\Categories\Models\Category $category |
||
180 | * |
||
181 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
||
182 | */ |
||
183 | protected function process(FormRequest $request, Category $category) |
||
184 | { |
||
185 | // Prepare required input fields |
||
186 | $data = $request->validated(); |
||
187 | |||
188 | // Save category |
||
189 | $category->fill($data)->save(); |
||
190 | |||
191 | return intend([ |
||
192 | 'url' => route('adminarea.categories.index'), |
||
193 | 'with' => ['success' => trans('cortex/foundation::messages.resource_saved', ['resource' => trans('cortex/categories::common.category'), 'identifier' => $category->name])], |
||
194 | ]); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Destroy given category. |
||
199 | * |
||
200 | * @param \Cortex\Categories\Models\Category $category |
||
201 | * |
||
202 | * @throws \Exception |
||
203 | * |
||
204 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
||
205 | */ |
||
206 | public function destroy(Category $category) |
||
207 | { |
||
208 | $category->delete(); |
||
209 | |||
210 | return intend([ |
||
211 | 'url' => route('adminarea.categories.index'), |
||
212 | 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/categories::common.category'), 'identifier' => $category->name])], |
||
213 | ]); |
||
214 | } |
||
215 | } |
||
216 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.