From 8dd2ee6393fe86cdc672db260e4e8450217a5643 Mon Sep 17 00:00:00 2001 From: cp6 Date: Wed, 2 Mar 2022 01:36:59 +1100 Subject: [PATCH] Added labels for reseller services Added labels for reseller services --- app/Http/Controllers/ResellerController.php | 25 +++++++++++++- resources/views/reseller/create.blade.php | 26 ++++++++++++++ resources/views/reseller/edit.blade.php | 38 +++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ResellerController.php b/app/Http/Controllers/ResellerController.php index 31fa913..0fc3662 100644 --- a/app/Http/Controllers/ResellerController.php +++ b/app/Http/Controllers/ResellerController.php @@ -109,6 +109,14 @@ class ResellerController extends Controller ); } + $labels_array = [$request->label1, $request->label2, $request->label3, $request->label4]; + + for ($i = 1; $i <= 4; $i++) { + if (!is_null($labels_array[($i - 1)])) { + DB::insert('INSERT IGNORE INTO labels_assigned (label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $reseller_id]); + } + } + Cache::forget('services_count');//Main page services_count cache Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache @@ -144,6 +152,11 @@ class ResellerController extends Controller $locations = DB::table('locations')->get(['*']); $providers = json_decode(DB::table('providers')->get(['*']), true); + $labels = DB::table('labels_assigned as l') + ->join('labels', 'l.label_id', '=', 'labels.id') + ->where('l.service_id', '=', $reseller->id) + ->get(['labels.id', 'labels.label']); + $ip_address = json_decode(DB::table('ips as i') ->where('i.service_id', '=', $reseller->id) ->get(), true); @@ -153,7 +166,7 @@ class ResellerController extends Controller ->where('s.id', '=', $reseller->id) ->get(['s.*', 'p.*']); - return view('reseller.edit', compact(['reseller', 'locations', 'providers', 'ip_address'])); + return view('reseller.edit', compact(['reseller', 'locations', 'providers', 'ip_address', 'labels'])); } public function update(Request $request, Reseller $reseller) @@ -215,6 +228,16 @@ class ResellerController extends Controller 'next_due_date' => $request->next_due_date, ]); + $deleted = DB::table('labels_assigned')->where('service_id', '=', $request->id)->delete(); + + $labels_array = [$request->label1, $request->label2, $request->label3, $request->label4]; + + for ($i = 1; $i <= 4; $i++) { + if (!is_null($labels_array[($i - 1)])) { + DB::insert('INSERT IGNORE INTO labels_assigned ( label_id, service_id) values (?, ?)', [$labels_array[($i - 1)], $request->id]); + } + } + $delete_ip = DB::table('ips')->where('service_id', '=', $request->id)->delete(); if (isset($request->dedicated_ip)) { diff --git a/resources/views/reseller/create.blade.php b/resources/views/reseller/create.blade.php index 830e087..da8ec7e 100644 --- a/resources/views/reseller/create.blade.php +++ b/resources/views/reseller/create.blade.php @@ -188,6 +188,32 @@ +
+
+ + label + label1 + +
+
+ + label + label2 + +
+
+ + label + label3 + +
+
+ + label + label4 + +
+
+
+
+ + label + label1 + @if(isset($labels[0]->id)) + {{$labels[0]->id}} + @endif + +
+
+ + label + label2 + @if(isset($labels[1]->id)) + {{$labels[1]->id}} + @endif + +
+
+ + label + label3 + @if(isset($labels[2]->id)) + {{$labels[2]->id}} + @endif + +
+
+ + label + label4 + @if(isset($labels[3]->id)) + {{$labels[3]->id}} + @endif + +
+
active === 1) ? 'checked' : '' }}>