Imran Ali
Imran Ali

Reputation: 392

Laravel Multisite Setup with Sub Domains

I want to build Laravel CMS with following requirements:

  1. Admin (manage all sites/database).
  2. Multi-sites (running on sub-domains, manage own database) each with API access.
  3. Same Codebase (can be replicated if needed).
  4. Same Database with different data for each site.

Can you please let me know how to setup this environment using Laravel 5.4.

Thanks.

Upvotes: 3

Views: 8404

Answers (2)

Imran Ali
Imran Ali

Reputation: 392

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.

Upvotes: 8

Jose Luis Otero
Jose Luis Otero

Reputation: 29

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

Upvotes: 0

Related Questions