Emulate a multi tenant CMS with payloadcms

default discord avatar
blupandaman
8 months ago
14

Is there a good way to model out multi tenant functionality within Payload? I was thinking having a sites collection that is used to create relationships between different media and blogs that would be on that site. Then I could have collections for the header, footer, pages, ect... for each site?



Is this the most sound way or is there a better way?

  • default discord avatar
    devskad
    8 months ago

    I am thinking the same thing, is their any hook for seeding the data to Payload for each site when installed a theme like as in wordpress?

  • default discord avatar
    martin.rahbek
    8 months ago
  • discord user avatar
    jacobsfletch
    Payload Team
    8 months ago

    Payload can absolutely be used for multi-tenancy. @martin.rahbek is exactly right in that this is achieved via access control. For example, you might have an "organizations" collection to represent your tenants, then you restrict access based on those organizations.

  • default discord avatar
    jarrod69420
    8 months ago

    @blupandaman This vid is might also be useful for you

    https://www.youtube.com/watch?v=DoPLyXG26Dg
  • default discord avatar
    blupandaman
    8 months ago

    Ok that makes sense. Thank you



    @jarrod69420 @jacobsfletch


    I'm looking to give users the ability to publish posts to multiple different blogs at a time. Would a good strategy be making a global called create multi post that allows a user to post the same content to multiple sites?

  • discord user avatar
    jacobsfletch
    Payload Team
    8 months ago

    With multi-tenancy you could add a

    hasMany

    relationship field to your

    posts

    collection and select each site(s) that the content belongs to. This way you only have to manage one document instead of many.

  • default discord avatar
    blupandaman
    8 months ago

    Ok makes sense. Would there be an easy way to create separate posts for each site? Just in case one site needs some info changed rather than all the sites?



    Would that br a job for the beforeChange hook?

  • discord user avatar
    jacobsfletch
    Payload Team
    8 months ago

    In that case they should be separate posts entirely and you should just use the built-in duplicate feature. The relationship field would still be needed, you just select one site, and not both.

  • default discord avatar
    blupandaman
    8 months ago

    I honestly didn't see that duplicate button until now! Thank you

  • discord user avatar
    jacobsfletch
    Payload Team
    4 months ago

    We now have an official multi-tenant example! Check it out:

    https://github.com/payloadcms/payload/tree/master/examples/multi-tenant
  • default discord avatar
    blupandaman
    4 months ago

    Thanks for the update!



    Will check it out

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.