belongsTo(User::class); } public function saveable(): MorphTo { return $this->morphTo(); } // Helper to get saved items by type public static function getSavedItemsForUser($userId, $type = null) { $query = self::with('saveable')->where('user_id', $userId); if ($type) { $query->where('saveable_type', $type); } return $query->latest()->get(); } // Check if user has saved specific item public static function isSavedByUser($userId, $saveableId, $saveableType) { return self::where([ 'user_id' => $userId, 'saveable_id' => $saveableId, 'saveable_type' => $saveableType, ])->exists(); } }