|
@@ -14,10 +14,17 @@ class StoreItemService
|
|
|
{
|
|
{
|
|
|
public function getAll(): Collection
|
|
public function getAll(): Collection
|
|
|
{
|
|
{
|
|
|
- return StoreItem::with(['category', 'media', 'variations'])
|
|
|
|
|
|
|
+ $userId = Auth::id();
|
|
|
|
|
+
|
|
|
|
|
+ $query = StoreItem::with(['category', 'media', 'variations'])
|
|
|
->withCount('interests')
|
|
->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
|
|
public function findById(int $id): ?StoreItem
|