PHPackages                             aljawad/laravel-multidomain - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aljawad/laravel-multidomain

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aljawad/laravel-multidomain
===========================

Laravel App on a subdomains, multi-tenancy setting

v1.1.0(7y ago)011MITPHP

Since Jun 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/buruhsd/laravel-multidomain)[ Packagist](https://packagist.org/packages/aljawad/laravel-multidomain)[ RSS](/packages/aljawad-laravel-multidomain/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (6)Used By (0)

[![Laravel](https://camo.githubusercontent.com/7d48a347cda33127449307a1ba24bdebf76d226c4f2a1585285c8e968f2666a9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![License](https://camo.githubusercontent.com/30597ff9a350144f03bffdd9183e16468e0b3ca1193e1d08591d992622738d55/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://tldrlegal.com/license/mit-license)

laravel-multidomain
===================

[](#laravel-multidomain)

A Laravel extension for using a laravel application on a multi domain setting

Description
-----------

[](#description)

This package allows to use a single laravel installation to work with multiple HTTP domains. There are many cases in which different customers use the same application in terms of code but not in terms of database, storage and configuration. With the use of this package is very simple to get a specific env file, a specific storage path and a specific database for each such a customer.

Documentation
-------------

[](#documentation)

### Installation

[](#installation)

Add gecche/laravel-multidomain as a requirement to composer.json:

```
{
    "require": {
        "gecche/laravel-multidomain": "1.1.*"
    }
}
```

Update your packages with composer update or install with composer install.

You can also add the package using composer require gecche/laravel-multidomain and later specifying the version you want (for now, dev-v1.1.\* is your best bet).

This package needs to override a minimal set of Laravel core functions as the detection of the HTTP domain in which the application is running is needed at the very first of the bootstrap process in order to get the specific environment file.

That premise implies that this package needs a bit more of "configuration steps" with respect to a standard laravel package.

The first action to take is to replace the whole Laravel container by modifying the following lines at the very top of the `app.php` file in the `bootstrap` folder.

```
//$app = new Illuminate\Foundation\Application(
$app = new Aljawad\Multidomain\Foundation\Application(
    realpath(__DIR__.'/../')
);
```

Then update also the two application Kernels (HTTP and CLI).

At the very top of the `Kernel.php` file in the `app\Http` folder, do the following changes:

```
use Aljawad\Multidomain\Foundation\Http\Kernel as HttpKernel;
//use Illuminate\Foundation\Http\Kernel as HttpKernel;
```

Similarly in the `Kernel.php` file in the `app\Console` folder:

```
use Aljawad\Multidomain\Foundation\Console\Kernel as ConsoleKernel;
#use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
```

The next step is to override the `QueueServiceProvider` with the extended one in the `$providers` array in the `app.php` file in the `config` folder:

```
        //Illuminate\Queue\QueueServiceProvider::class,
        Aljawad\Multidomain\Queue\QueueServiceProvider::class,
```

Lastly you publish the config file.

```
php artisan vendor:publish

```

This package makes use of the discovery feature. Following the above steps your application will be aware of the HTTP domain in which is running both for HTTP and CLI requests (including queue support).

### Usage

[](#usage)

This package releases three commands to manage your application HTTP domains.

#### `domain.add` command

[](#domainadd-command)

The main command is the `domain:add` command which takes as argument the name of the HTTP domain to add to the application. Let us suppose to have two domains `site1.com`and `site2.com` sharing the same code.

We simply do:

```
php artisan domain:add site1.com

```

and

```
php artisan domain:add site2.com

```

Above commands simply create two new environemnt files, namely `.env.site1.com` and `.env.site2.com`in which you can put all the specific configuration for each site, e.g. databases configuration, cache configuration and each other configuration as for the usual environment file. In addition, within the standard `storage` folder, two new folders have been created, namely `site1_com` and `site2_com` with the same substructure in terms of folders of the main storage one. In particular, the folder structure within the new storage folders can be customized in the `domain.php` config file.

#### Distinguishing between HTTP domains

[](#distinguishing-between-http-domains)

For each HTTP request received by the application, the specific environment file is loaded and the specific storage folder is used. If not specific environment file and/or storage folder has been found, the standard ones are used. The detection of the right HTTP domain is done by using the `$_SERVER['SERVER_NAME']`PHP variable.

In order to distinguishing between domains use artisan commands (including queue stuff), each artisan command accepts now a new option `domain`. E.g.:

```
php artisan list --domain=site1.com

```

#### `domain.remove` command

[](#domainremove-command)

The `domain:remove` command simply removes the specified HTTP domain from the application by deleting its environment file. The use of the `force` option, allows to delete also the domain storage folder. E.g.:

```
php artisan domain:remove site2.com

```

#### `domain.update_env` command

[](#domainupdate_env-command)

The `domain:update_env` command allows to update one or all the environemnt files by passing a json encoded array of data to be added at the end of such files. By using the `domain` option, only one environment file is updated. With no `domain` option, the command updates all the environment files, including the standard `.env` one. The list of domains to be updated is maintained in the `domain.php` config file. The `domain:add` and the `domain:remove` add and remove respectively an entry in the `domains` array in this file. E.g.:

```
php artisan domain:update_env --domain_values='{"TOM_DRIVER":"TOMMY"}'

```

adds the line `TOM_DRIVER=TOMMY` to all the found environment files.

#### Further information

[](#further-information)

At run-time, the current HTTP domain is maintained in the laravel container and can be accessed by its `domain()` method added by this package.

Compatibility
-------------

[](#compatibility)

v1.1 requires Laravel 5.5+

v1.0 requires Laravel 5.1+ (no longer maintained and not tested versus laravel 5.4, however the usage of the package is the same ad for 1.1)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 76.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~155 days

Total

5

Last Release

2616d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94a4ffcd3cb3a01bb30db6232c7f24edbb6144a8fdd13200e5744a5ec25d59d9?d=identicon)[buruhsd](/maintainers/buruhsd)

---

Top Contributors

[![gecche](https://avatars.githubusercontent.com/u/11093763?v=4)](https://github.com/gecche "gecche (16 commits)")[![buruhsd](https://avatars.githubusercontent.com/u/3405292?v=4)](https://github.com/buruhsd "buruhsd (5 commits)")

---

Tags

laraveldomainmultidomain

### Embed Badge

![Health badge](/badges/aljawad-laravel-multidomain/health.svg)

```
[![Health](https://phpackages.com/badges/aljawad-laravel-multidomain/health.svg)](https://phpackages.com/packages/aljawad-laravel-multidomain)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
