Implementing Multi-tenancy in Laravel - php

I am using Laravel 5.4 with having Laravel Voyager Installed.
The main requirements of the project are to have the multi-tenant domain based application i.e. app.com and {client}.app.com
I have been trying to load configurations based on a subdomain and will act subdomain as the client code
which worked fine on localhost but while I am pushing changes to live server things are not working
As a beginner in this scope, I am not sure how thing will work on the live environment, in terms of domain redirection and setting up options in middleware, or mainly how wildcard subdomain would work in laravel's subdomain routing

You can use this package: https://github.com/hyn/multi-tenant
I've used this many times and can confirm it works extremely well. As an added bonus, there's a very detailed tutorial you can use to get going here: https://laravel-tenancy.com/docs/hyn/5.x/full-featured-tutorial

Related

Subdomain for Laravel Rest API not working correctly - IONOS using Plesk

I've got a VPS with IONOS (was 1&1) and running Plesk Obsidian and I am up to date using Laravel 9. Now I've hit a snag, all I want to do is add a simple subdomain :-
api.trolleyspotting.fun
So what would be https://trolleyspotting.fun/api/v1/trolleys/all
points to
https://api.trolleyspotting.fun/v1/trolleys/all
My issue is when I add the following code to routes/api.php
Route::domain('api.' . env('APP_URL'))->group(function() {
`Route::get('v1/trolleys/all', [ApiController:class, 'index']);`
});
And then go to https://api.trolleyspotting.fun/v1/trolleys/all nothing happens! I added an A record for the subdomain in IONOS Domain control panel and it points to the VPS IP address. When I install the laravel application and try to do as above it just does not work. Where am I going wrong? It's added no problem on the Plesk side as a subdomain. Do I need to add something in routes/web.php ? I've tried just adding the A record for the subdomain and adding it to the DNS side on Plesk but not physically adding it as a subdomain with its own directories but that didn't work either. I am reaching the end of my patience because I'm not a novice and I have read up but no solutions on here or in tutorials (YouTube too) have worked.
Any advice or answers very much appreciated in advance.
Thanks!
I would like to suggest you a simple and straight forward way to implement it.
If you want to use sub-domain(like: api.xyz.com) map it from the subdomain management from hosting provider
Point it to the public folder of your current laravel app deployment so it will work simple as api.xyz.com/api/{version}/{route_name}
i think you should follow this steps and you are good to go.

URLs with domain name in symfony

I'm pretty new to working with Symfony and I cannot find a way around my problem:
I have a domain, say testing.domain.tld where I deploy my app for testing purposes. Routing works as expected for all my self written controllers, but when i send an email or in easyadmin, the generated URL is something like 127.0.0.1:8080/route instead of testing.domain.tld/route.
This can probably be done in config, but I do not see where/how...
I would be very thankful for any hints!
You have to configure the router request context base url. If you are using at least Symfony 5.1 you can configure it via the framework.router.default_uri configuration key, otherwise you have to specify the host, scheme and base path of your application.
Read more about this feature in this post from symfony blog

Custom Domain mapping in cloud based application

I am creating a cloud based application in laravel/php.
I have a functionality where user can have their website at user.myapp.com and it works (with subdomain and model binding).
I now want to go one step further, and allow users to add their own custom domain names. So their website will be reachable at user-domain.com rather than (or as well as) user.myapp.com.
I want to understand how to do this. I'm using Laravel framework which is based on php and apache.
What kind of server do I need? Can I use shared hosting?
What configs do I need to do in order for this to work?
What DNS record the user must create to put things together?
You can do this with any kind of server. You can make a route that is caught by any domain and in the controller of this route, you can query the database to know what website should be displayed for that domain.
You can get the domain name of the current request using app('request')->root();

Laravel Multisite Setup with Sub Domains

I want to build Laravel CMS with following requirements:
Admin (manage all sites/database).
Multi-sites (running on sub-domains, manage own database) each with API access.
Same Codebase (can be replicated if needed).
Same Database with different data for each site.
Can you please let me know how to setup this environment using Laravel 5.4.
Thanks.
This project has been finished now. So posting my own solution for the question.
Following are points to take care:
I've used Laravel 5.4 (later upgraded to 5.5).
For multi tenancy used Landlord extension for Laravel.
Server is configured to listen for wild-card sub-domains.
Each site is running on sub-domain.
Using single database with site-id (tenant-id) under each DB table.
Whenever server gets request, sub-domain is matched with tenant id in the middleware & load all the records for that tenant only.
I've hope this might help someone else.
For build a Laravel CMS with following requirements you need use:
You can set an Admin Role with policies and gates or uses entrust
For Multi-sites, You can used something like https://github.com/hyn/multi-tenant, so If you use multitenant you can
Multi-sites (running on sub-domains, manage own database) each with
API access. Same Codebase (can be replicated if needed). Same
Database with different data for each site.
For config subdomain you can read the official documentation https://laravel.com/docs/5.4/routing#route-group-sub-domain-routing

Symfony2 ignore certain route

I have the following situation:
I'm running a Symfony 2 project on a server with the route www.homepage.de.
Every request to a random route on www.homepage.de will be routed to my Landing Page.
Now I want to integrate another project, an API build with Slim PHP and Swagger UI, into this Symfony 2 project. I cloned the project into the /web directory of the Symfony2 project to gurantee access to it.
But now every request I want to do to www.homepage.de/api fails because the Symfony 2 project wants to handle the request and can't find the route. Is there a possibility to tell Symfony2 to ignore every request that is send to the www.homepage.de/api route?
First of all don't add anything to web folder of your application. Just create two applications in different folders. If you want the API to be accessible through the same domain but just with /api you cen use either mod_alias or mod_rewrite to achieve this.
In your current solution it is not Symfony that is intercepting your requests. Take a look at your .htaccess. This is where the magic happens. You can always modify rewrite rules to intercept all /api requests and redirect them to your application but I would still suggest to keep those projects apart.

Categories