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.
Detect the domain or sub domain and query it against the database
Get the relevant id from a table storing the domains
Set the id in a session or a global variable
Get the settings of the site using that key
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
How to load the domain id and settings from database before code in controller is executed. Just like the configuration file in laravel
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 :)
Have a look at the package delatbabel / site-config, it sounds like it does most of what you want. Search on packagist or github. It will pre populate the laravel config data based on database contents, depending on what domain The browser is pointing to.
Related
I have a web app built using Laravel and MySQL. It's currently running on my www.domain.com
I would like to know how to "duplicate" the web app to a subdomain with a separated database?
The web app has login and signup features. There's also email notification sent to clients if they sign up, make changes, etc.
The reason I'm doing this is because I have two types of clients, local and overseas clients. Therefore I have to separate them since they use different currencies and languages. So, when my team login to the subdomain, they'll know they have to speak in our local language, but when they login to the www.domain.com, they'll know they have to speak English.
Thanks very much, will appreciate any help
UPDATE The database has been successfully copied to a new database, however the sign up and login pages of the subdomain are linked to the main domain.
You could look up https://hyn.readme.io which does pretty much exactly what you want. It lets you setup new tenants which are assigned a subdomain and creates a separate database while at the same time sharing your actual application between them all.
If needed you can add tenant-specific overrides of the default apps views and whatnot by adding them to the tenants own folders.
According to your comment earlier, you are getting error in phpMyAdmin when trying to upload database. Why not just copy the database in phpMyAdmin? Go to database you want click on Operations then under Copy Database type name of new database and select copy structure and data. That should solve your issue.
I have a hybrid WordPress plugin that fetches all data using curl from the main server. Let's call it A.
B is the client that requests for data and also can send data to A.
Now every request is encrypted and authenticated using a API access keys.
But the problem here is if I copy the plugin from B to a new client site C, the moment I use the same access keys etc. the plugin starts working.
I want to be able to restrict the access of one API access key to one domain name. How can I attain that?
I'd say to include the allowed host's IP address (B) in your access key administration.
So: when B does a call, you can validate the key and the IP it's calling from.
On A, you can use something like $_SERVER['REMOTE_ADDR'] to test the IP calling the script.
Two downsides: when sites move servers, the plugin will stop working. And of course, people can still spoof their IP, so there is a way to get around this, but at least you make it a lot more complicated and probably not worth the hassle for most cases.
A suggestion by TJHX
Make it part of the license you give your customers. The honest ones will follow it, the dishonest ones will find a way to break your DRM. This is a problem technology can't really solve confidently, especially when with things like wordpress people can just see your code - By TJHX
I have also looked into a lot of options but the mere fact is that the user always has access to the code in the wordpress plugin and can easily make amendments to the CURL request Headers even if you encrypt it.
All we can do it add it in our Licenses.
In my plugin, there are iframes that will be loading the data on the frontend so I am going to accept the domain name when the user buys the plugin and will check the referrers to my iframe to sort this issue out.
Thanks a lot guys for your help.
i am currently learning laravel and was wondering if its possible to load different customizations under each domain while using a single installation of laravel. let me explain what i mean.
if customer A has a has signed up to use my app and requested a few customizations to be done such as certain data be populated under a view or some kind of module that does something, i only want those to only be visible to him so that if customer b signs up he wont see the featues given to customer a.
Usually what companies does is have a copy of the app uploaded for each customer under their own hosting and each customer can have his or her own customization but when it comes time to upgrade you would have to update each app one by one and hope that nothing breaks.
Is there a way to just use one core installation of an app and have the customizations be loaded uniquly for each customer? would this be called multitennancy? or that terms means something else completly.
Sorry if i sound vague in any way its just that its something that ive wondered since day 1 of being a web developer and have seen many companies do what i mentioned above and i see this as bad practice and can be done better. but please correct me if im wrong.
ps: i know it must be possible because ive seen how with wordpress which has the multusite feature turned on, you can have a complete different views or plugins turned on or off per domain under a single installation of wp.
We want to create Magento Stores and Store views programmatically in a Multi Store environment but can't find any info that doesn't send me to the dashboard. We are making many stores for remote users and would like to, either accelerate our process with a batch file or, better yet, allow remote users to set up their stores from a Wordpress based site.
One possibility is fiddling with the appropriate tables in the DataBase but we don't want to miss any crucial aspect. We would prefer to instruct Magento to create the store and view ensuring it's done correctly.
Any ideas?
Thanks!
Found this link from Stackoverflow: How to create a site,store and view programatically in magento
Didn't see it when I searched for the answer in Stackoverflow before eventhough it's almost identical.
I'll try it out and get back to you all.
I need to build a strategy or plan for implementation of a site
the situation is the following:
i have a site for people which belong to a community say xyz.
now i need to provide an account for the individuals of such communities on my site
when they logs into my site, there will be a feature to build a portal for themselves with some functionalities
like wise when n no of people logs in they might create n no of portal for themselves with some functionalities
the people will also create or use a n no of domain name respectively for the portal.
my problem or questions is:
How can i plan to create such a website?
Do i have to create separate code base files for each individual portal? or my current website portal code base can serve for each individual created portals?
How can i setup the site at domain automatically?
Update 1
I think the main website will already have a domain name for it
The other portals created through the main website will also have domain name for themselves as they are for some users
but the question is i have my main website domain name already using the code base which is serving the main website, now can i create domain names through my main website for the users and also ask the newly created domain names to use the same code base of my main website?
Actually i am planning to create domains through my application(please guide how can i create domain from my application) than after creating the domain can i ask the newly created domain to use the code base of my website which created the domain.
than there in the code base i do a domain name check as suggested in few other forums i guess, and load the content for the portal in the newly created domin
is this possible? if yes also can you guide me how can i:
create domains from my application? and than
during domain creation process through my application, how can i configure the new domain being created to my application code base?
is this the right way of implementing it?
1) How can i plan to create such a website?
Think about what exactly it is that the user requires. They have made an account, and want a portal to their own personal domain on the server. A domain on a server is just a file, so when they create that new portal, you might want to simply add a new HTML file under a logical directory, and populate it with some standard HTML.
2)Do I have to create separate code base files for each individual portal? or my current website portal code base can serve for each individual created portals?
I guess you can make the difference specified by a query string in the URL. For example, add database values for each user, and do something like this:
www.mywebsite.com/portal.php?id=40395
Your page will then use that id value, and take values from the database to populate the page with. That way you only have one file, portal.php, but it serves for any number of people.
3)How can i setup the site at domain automatically?
Like I said, the domain is just a file on the server. For example:
www.mywebsite.com/files/directory/hello.php
is just referring to the structure of files on the server. Namely:
www.mywebsite.com
files
directory
hello.php
If you place a file, goodbye.php in the same place, you can access it in a similar way.
www.mywebsite.com/files/directory/goodbye.php
PLEASE NOTE : You have provided no code, so I don't feel obliged to provide any in return. If you haven't took a swing at the problem of implementing the solution, then I guess I won't either.