Parcourir la source

funcao para abrir wpp com mensagem pre preenchida para msg da serprati

Gustavo Zanatta il y a 1 mois
Parent
commit
ffeb55a95a
1 fichiers modifiés avec 10 ajouts et 3 suppressions
  1. 10 3
      app/Services/StoreItemService.php

+ 10 - 3
app/Services/StoreItemService.php

@@ -14,10 +14,17 @@ class StoreItemService
 {
     public function getAll(): Collection
     {
-        return StoreItem::with(['category', 'media', 'variations'])
+        $userId = Auth::id();
+
+        $query = StoreItem::with(['category', 'media', 'variations'])
             ->withCount('interests')
-            ->orderBy('name')
-            ->get();
+            ->orderBy('name');
+
+        if ($userId) {
+            $query->withExists(['interests as user_interested' => fn($q) => $q->where('user_id', $userId)]);
+        }
+
+        return $query->get();
     }
 
     public function findById(int $id): ?StoreItem