浏览代码

fix: 🐛 Check if product supports the exact egg as server installed on

IceToast 2 年之前
父节点
当前提交
e9348eca52
共有 2 个文件被更改,包括 15 次插入11 次删除
  1. 10 3
      app/Http/Controllers/ServerController.php
  2. 5 8
      resources/views/servers/settings.blade.php

+ 10 - 3
app/Http/Controllers/ServerController.php

@@ -228,10 +228,17 @@ class ServerController extends Controller
 
         $server->node = $serverRelationships['node']['attributes']['name'];
         $server->name = $serverAttributes['name'];
-        $product = Product::orderBy("created_at")->get();
-        return view('servers.settings')->with([ 
+        $server->egg = $serverRelationships['egg']['attributes']['name'];
+        $products = Product::orderBy("created_at")->get();
+
+        // Set the each product eggs array to just contain the eggs name
+        foreach ($products as $product) {
+            $product->eggs = $product->eggs->pluck('name')->toArray();
+        }
+
+        return view('servers.settings')->with([
             'server' => $server,
-            'product' => $product
+            'products' => $products
         ]);
     }
 

+ 5 - 8
resources/views/servers/settings.blade.php

@@ -21,7 +21,7 @@
         </div>
 
     </section>
-    <!-- END CONTENT HEADER --> 
+    <!-- END CONTENT HEADER -->
 
     <!-- MAIN CONTENT -->
     <section class="content">
@@ -104,7 +104,7 @@
                         </div>
                         <div class="col-4 text-end">
                           <div class="icon icon-shape bg-gradient-warning shadow-warning text-center rounded-circle">
-                            <i class='bx bxs-hdd' style="color: white;"></i>                
+                            <i class='bx bxs-hdd' style="color: white;"></i>
                           </div>
                         </div>
                       </div>
@@ -247,15 +247,12 @@
                                     @csrf
                                         <select name="product_upgrade" id="product_upgrade" class="form-input2 form-control">
                                           <option value="">Select the product</option>
-                                            @foreach($product as $product)
-                                                @if($product->eggs[0]->nest->id == $server->product->eggs[0]->id)
-                                                  @if ($product->id != $server->product->id)
+                                            @foreach($products as $product)
+                                                @if(in_array($server->egg, $product->eggs) && $product->id != $server->product->id)
                                                   <option value="{{ $product->id }}">{{ $product->name }} [ {{ CREDITS_DISPLAY_NAME }} {{ $product->price }} ]</option>
-
-                                                  @endif
                                                 @endif
                                             @endforeach
-                                        </select> 
+                                        </select>
                                         <br> Once the Upgrade button is pressed, we will automatically deduct the amount for the first hour according to the new product from your credits. <br>
                                     </div>
                                     <div class="modal-footer card-body">