diff --git a/app/Http/Controllers/SharedController.php b/app/Http/Controllers/SharedController.php index a66dca4..42fbe7f 100644 --- a/app/Http/Controllers/SharedController.php +++ b/app/Http/Controllers/SharedController.php @@ -96,6 +96,14 @@ class SharedController extends Controller 'next_due_date' => $request->next_due_date, ]); + $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)], $shared_id]); + } + } + return redirect()->route('shared.index') ->with('success', 'Shared hosting created Successfully.'); } @@ -121,14 +129,17 @@ class SharedController 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', '=', $shared->id) + ->get(['labels.id', 'labels.label']); $shared = DB::table('shared_hosting as s') ->join('pricings as p', 's.id', '=', 'p.service_id') ->where('s.id', '=', $shared->id) ->get(['s.*', 'p.*']); - - return view('shared.edit', compact(['shared', 'locations', 'providers'])); + return view('shared.edit', compact(['shared', 'locations', 'providers', 'labels'])); } public function update(Request $request, Shared $shared) @@ -193,6 +204,16 @@ class SharedController 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]); + } + } + return redirect()->route('shared.index') ->with('success', 'Shared hosting updated Successfully.'); } diff --git a/resources/views/shared/create.blade.php b/resources/views/shared/create.blade.php index 2373c43..ee86da5 100644 --- a/resources/views/shared/create.blade.php +++ b/resources/views/shared/create.blade.php @@ -190,6 +190,32 @@ +
+
+ + label + label1 + +
+
+ + label + label2 + +
+
+ + label + label3 + +
+
+ + label + label4 + +
+
@@ -200,7 +200,8 @@
Domains
-
@@ -222,7 +223,8 @@
Email
-
@@ -241,7 +243,8 @@
FTP
-
@@ -253,8 +256,47 @@ +
+
+ + 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' : '' }}> + active === 1) ? 'checked' : '' }}>