orderBy('name')->get(); } public function findById(int $id): ?StoreItem { return StoreItem::with(['category', 'media'])->find($id); } public function create(array $data): StoreItem { return StoreItem::create($data); } public function update(int $id, array $data): ?StoreItem { $model = StoreItem::find($id); if (!$model) { return null; } $model->update($data); return $model->fresh(['category']); } public function delete(int $id): bool { $model = StoreItem::find($id); if (!$model) { return false; } return $model->delete(); } public function getMyInterests(): Collection { $userId = Auth::id(); return StoreItem::with('category') ->whereHas('interests', fn($q) => $q->where('user_id', $userId)) ->orderBy('name') ->get(); } public function toggleInterest(int $storeItemId): array { $userId = Auth::id(); $existing = StoreItemInterest::where('user_id', $userId) ->where('store_item_id', $storeItemId) ->first(); if ($existing) { $existing->delete(); return ['interested' => false]; } StoreItemInterest::create(['user_id' => $userId, 'store_item_id' => $storeItemId]); return ['interested' => true]; } }