belongsTo(User::class); } public function likeable(): MorphTo { return $this->morphTo(); } // Helper methods public static function getLikedItemsForUser($userId, $type = null) { $query = self::with('likeable')->where('user_id', $userId); if ($type) { $query->where('likeable_type', $type); } return $query->latest()->get(); } public static function isLikedByUser($userId, $likeableId, $likeableType) { return self::where([ 'user_id' => $userId, 'likeable_id' => $likeableId, 'likeable_type' => $likeableType, ])->exists(); } public static function getLikeCount($likeableId, $likeableType) { return self::where([ 'likeable_id' => $likeableId, 'likeable_type' => $likeableType, ])->count(); } }