October CMS.. Create User With Different Database

- 1 answer

I am trying to build a multi user system and each user has different database.. is it possible in october cms.. So all the user access one login url.. So i don't need to install another fresh octobercms in the server..



I think you're referring to a Multitenancy.

You basically have two options :

a) Shared Database

b) Multi tenant Databases ( What you are asking )

Have a look at this laravel package to get an idea how to implement it but Keep in mind that building model relations across databases can be a pain and don't forget about future migrations ect..

The general idea here is (b) ;

  • Create a Tenant / Users Table on your Main Database
  • Store in this table each user's access info ( Host, DB Access .. )
  • Create Middlewares to handle logins, database connections, redirects, security for each requests..

If you're just playing around there's nothing wrong with it but I wouldn't recommend it for a commercial project unless you're experienced enough.

Having said that, If you want to proceed with option (a) all you need to do is add a tenant_id field to all tables / relations and to all queries as a security precaution.