The recent experimental observation of spinor self-ordering of ultracold atoms in optical resonators has set the stage for the exploration of emergent magnetic orders in quantum-gas-cavity systems. Based on this platform, we introduce a generic scheme for the implementation of longrange quantum spin Hamiltonians composed of various types of couplings, including Heisenberg and Dzyaloshinskii-Moriya interactions. Our model is comprised of an effective two-component Bose-Einstein condensate, driven by two classical pump lasers and coupled to a single dynamic mode of a linear cavity in a double Λ scheme. Cavity photons mediate the long-range spin-spin interactions with spatially modulated coupling coefficients, where the latter ones can be tuned by modifying spatial profiles of the pump lasers. As experimentally relevant examples, we demonstrate that by properly choosing the spatial profiles of the pump lasers achiral domain-wall antiferromagnetic and chiral spin-spiral orders emerge beyond critical laser strengths. The transition between these two phases can be observed in a single experimental setup by tuning the reflectivity of a mirror. We also discuss extensions of our scheme for the implementation of other classes of spin Hamiltonians.Introduction.-Quantum magnetism plays a crucial role in many phenomena in condensed matter physics [1], including for instance high-temperature superconductivity [2] and spin liquids [3]. In materials, there exist different forms of interactions between electronic spins. The Heisenberg interaction, originating from the isotropic quantum exchange interaction between electrons, favors ferromagnetic (FM) or antiferromagnetic (AFM) ordering [4]. The more exotic Dzyaloshinskii-Moriya (DM) interaction [5][6][7], stemming from a relativistic antisymmetric exchange interaction, favors chiral states such as spin spiral (SS) and skyrmion [8][9][10][11][12][13][14][15], with potential applications in spintronics [16].