|
|
@@ -0,0 +1,36 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers;
|
|
|
+
|
|
|
+use App\Http\Requests\FilterRequest;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+class FilterController extends Controller
|
|
|
+{
|
|
|
+ const DB_TABLES = [
|
|
|
+ 'orders' => 'orders_view',
|
|
|
+ 'product_sku' => 'mafs_view',
|
|
|
+ 'products' => 'products',
|
|
|
+ 'reclamations' => 'reclamations',
|
|
|
+ 'maf_order' => 'maf_orders_view',
|
|
|
+ ];
|
|
|
+ public function getFilters(FilterRequest $request)
|
|
|
+ {
|
|
|
+ $table = $request->validated('table');
|
|
|
+ $column = $request->validated('column');
|
|
|
+ if(!array_key_exists($table, self::DB_TABLES)) {
|
|
|
+ abort(400, 'Table not found');
|
|
|
+ }
|
|
|
+
|
|
|
+ $dbTable = self::DB_TABLES[$table];
|
|
|
+
|
|
|
+ $q = DB::table($dbTable)->select($column)->distinct();
|
|
|
+ if($table !== 'reclamations') {
|
|
|
+ $q->where('year' , year());
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = $q->orderBy($column)->get()->pluck($column)->toArray();
|
|
|
+
|
|
|
+ return response()->json($result, 200, [], JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
|
|
+ }
|
|
|
+}
|