samedi 19 mars 2016

Multiple Domains and Domain Specific database queries in Laravel

So we have been developing a content management system on laravel and everything is finished. Our plan was to ship it as downloadable solution for customers but now things have changed and we have decided that we will provide it as a SAAS. As it will be used by multiple customers and they will be either using their own domain or our subdomain, I figured out the following solution.

  1. Detect the domain or sub domain and query it against the database
  2. Get the relevant id from a table storing the domains
  3. Set the id in a session or a global variable
  4. Get the settings of the site using that key
  5. For all the subsequent queries to database, add a default where('domain_id',$idOfDomain) so that to avoid mixing up of the data by users of different clients

I don't know if that's the best approach but currently i feel like it's the solution. Now the problem is that I don't know

  1. How to load the domain id and settings from database before code in controller is executed. Just like the configuration file in laravel
  2. I tried to set a default key on models but it was not much successful and I want to know how to set and retrieve domain id in all models as editing all the codes in controller will be too much time consuming

Besides if someone has better and secure solution then the above one then please share it.

Thanks :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire