Browse Source

fixed product disabled not working properly

AVMG20 3 năm trước cách đây
mục cha
commit
180afb9ef5

+ 7 - 3
app/Http/Controllers/ProductController.php

@@ -24,9 +24,12 @@ class ProductController extends Controller
         if (is_null($egg->id)) return response()->json('Egg ID is required', '400');
 
         #get products that include this egg
-        $products = Product::query()->with('nodes')->whereHas('eggs', function (Builder $builder) use ($egg) {
-            $builder->where('id', '=', $egg->id);
-        })->get();
+        $products = Product::query()
+            ->with('nodes')
+            ->where('disabled', '=', false)
+            ->whereHas('eggs', function (Builder $builder) use ($egg) {
+                $builder->where('id', '=', $egg->id);
+            })->get();
 
         $nodes = collect();
 
@@ -39,6 +42,7 @@ class ProductController extends Controller
             });
         });
 
+
         return $nodes;
     }
 

+ 16 - 8
app/Http/Controllers/ServerController.php

@@ -35,16 +35,24 @@ class ServerController extends Controller
         if (!is_null($this->validateConfigurationRules())) return $this->validateConfigurationRules();
 
         $productCount = Product::query()->where('disabled', '=', false)->count();
-
-        $nodeCount = Node::query()->has('products')->count();
-
-        $eggs = Egg::query()->has('products')->get();
-
         $locations = Location::all();
 
-        $nests = Nest::query()->whereHas('eggs', function (Builder $builder) {
-            $builder->has('products');
-        })->get();
+        $nodeCount = Node::query()
+            ->whereHas('products', function (Builder $builder) {
+                $builder->where('disabled', '=', false);
+            })->count();
+
+        $eggs = Egg::query()
+            ->whereHas('products', function (Builder $builder) {
+                $builder->where('disabled', '=', false);
+            })->get();
+
+        $nests = Nest::query()
+            ->whereHas('eggs', function (Builder $builder) {
+                $builder->whereHas('products', function (Builder $builder) {
+                    $builder->where('disabled', '=', false);
+                });
+            })->get();
 
         return view('servers.create')->with([
             'productCount' => $productCount,