Code Monkey home page Code Monkey logo

laravel-multidomain's Introduction

License Laravel Laravel Laravel Laravel Laravel Laravel Laravel

Laravel Multi Domain

An extension for using Laravel in a multi domain setting

Laravel Multi Domain

Description

This package allows 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.

This package gives a very simple way to get a specific env file, a specific storage path and a specific database for each such customer.

Documentation

Version Compatibility

Laravel Multidomain
11.x 11.x
10.x 10.x
9.x 5.x
8.x 4.x
7.x 3.x
6.x 2.x
5.8.x 1.4.x
5.7.x 1.3.x
5.6.x 1.2.x
5.5.x 1.1.x

Further notes on Compatibility

Releases v1.1.x:

  • From v1.1.0 to v1.1.5, releases are fully compatibile with Laravel 5.5, 5.6, 5.7, 5.8 or 6.0.
  • From v1.1.6+ releases v1.1.x are only compatible with Laravel 5.5 in order to run tests correctly.

To date, releases v1.1.6+, v1.2.x, v1.3.x, v1.4.x, v2.x and v3.x are functionally equivalent. Releases have been separated in order to run integration tests with the corresponding version of the Laravel framework.

However, with the release of Laravel 8, releases v1.1.14, v1.2.8, v1.3.8 and v1.4.8 are the last releases including new features for the corresponding Laravel 5.x versions (bugfix support is still active for that versions). 2021-02-13 UPDATE: some last features for v1.1+ releases are still ongoing :)

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

2023-02-20 UPDATE: From Laravel 10.x up, the package versions follow the same numbering.

Installation

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

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

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 specify the version you want.

This package needs to override the detection of the HTTP domain in a minimal set of Laravel core functions at the very start of the bootstrap process in order to get the specific environment file. So this package needs a few more configuration steps than most Laravel packages.

Installation steps:

  1. replace the whole Laravel container by modifying the following lines at the very top of the bootstrap/app.php file.
//use Illuminate\Foundation\Application
use Gecche\Multidomain\Foundation\Application
  1. Override the QueueServiceProvider with the extended one in the config/app.php file as follows:
    'providers' => \Illuminate\Support\ServiceProvider::defaultProviders()->merge([
        // Package Service Providers...
    ])->replace([
      \Illuminate\Queue\QueueServiceProvider::class => \Gecche\Multidomain\Queue\QueueServiceProvider::class,
    ])->merge([
        // Added Service Providers (Do not remove this line)...
    ])->toArray(),

Please note that if you changed the config/app.php file due to other reasons, probably there is already the above providers entry in that file and the only important line is the one which replaces the QueueServiceProvider.

  1. 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.

NOTE: in Laravel 11 the installation is simpler than before: if you use a previous version of Laravel, please check in the documentation the installation steps.

Laravel Horizon installation:

The package is compatible with Horizon, thatnks to community contributions. If you need to use this package together with Horizon you have to follow other two installation steps:

  1. Install Laravel Horizon as usual

  2. Replace the Laravel Horizon import at the very top of the app/Providers/HorizonServiceProvider.php file.

//use Laravel\Horizon\HorizonApplicationServiceProvider;
use Gecche\Multidomain\Horizon\HorizonApplicationServiceProvider;

Usage

This package adds three commands to manage your application HTTP domains:

domain.add artisan 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 we 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 

These commands create two new environment files, .env.site1.com and .env.site2.com, in which you can put the specific configuration for each site (e.g. databases configuration, cache configuration and other configurations, as usually found in an environment file).

The command also adds an entry in the domains key in config/domains.php file.

In addition, two new folders are created, storage/site1_com/ and storage/site2_com/. They have the same folder structure as the main storage.

Customizations to this storage substructure must be matched by values in the config/domain.php file.

domain.remove artisan command

The domain:remove command removes the specified HTTP domain from the application by deleting its environment file. E.g.:

php artisan domain:remove site2.com 

Adding the force option will delete the domain storage folder.

The command also removes the appropriate entry from, the domains key in config/domains.php file.

domain.update_env artisan command

The domain:update_env command passes a json encoded array of data to update one or all of the environment files. These values will be added at the end of the appropriate .env.

Update a single domain environment file by adding the domain argument.

When the domain argument is absent, 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.

E.g.:

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

will add the line TOM_DRIVER=TOMMY to all the domain environment files.

domain.list artisan command

The domain:list command lists the currently installed domains, with their .env file and storage path dir.

The list is maintained in the domains key of the config/domain.php config file.

This list is automatically updated at every domain:add and domain:remove commands run.

config:cache artisan command

The config:cache artisan command can be used with this package in the same way as any other artisan command.

Note that this command will generate a file config.php file for each domain under which the command has been executed. I.e. the command

php artisan config:cache --domain=site2.com 

will generate the file

config-site2_com.php 

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.

A domainList() method is available. It returns an associative array containing the installed domains info, similar to the domain.list command above.

E.g.

[ 
   site1.com => [
       'storage_path' => <LARAVEL-STORAGE-PATH>/site1_com,
       'env' => '.env.site1.com'
   ]
] 

Distinguishing between HTTP domains in web pages

For each HTTP request received by the application, the specific environment file is loaded and the specific storage folder is used.

If no specific environment file and/or storage folder is found, the standard one is used.

The detection of the right HTTP domain is done by using the $_SERVER['SERVER_NAME'] PHP variable.

IMPORTANT NOTE: in some execution environments $_SERVER['SERVER_NAME'] is not instantiated, so this package does not work properly until you customize the detection of HTTP domains as described below.

Customizing the detection of HTTP domains

Starting from release 1.1.15, the detection of HTTP domains can be customized passing a Closure as the domain_detection_function_web entry of the new domainParams argument of Application's constructor. In the following example, the HTTP domain detection relies upon $_SERVER['HTTP_HOST'] instead of $_SERVER['SERVER_NAME'].

//use Illuminate\Foundation\Application;
use Gecche\Multidomain\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

$environmentPath = null;

$domainParams = [
    'domain_detection_function_web' => function() {
        return \Illuminate\Support\Arr::get($_SERVER,'HTTP_HOST');
    }
];

return Application::configure(basePath: dirname(__DIR__),
    environmentPath: $environmentPath,
    domainParams: $domainParams)
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

Using multi domains in artisan commands

In order to distinguishing between domains, each artisan command accepts a new option: domain. E.g.:

php artisan list --domain=site1.com 

The command will use the corresponding domain settings.

About queues

The artisan commands queue:work and queue:listen commands have been updated to accept a new domain option.

php artisan queue:work --domain=site1.com 

As usual, the above command will use the corresponding domain settings.

Keep in mind that if, for example, you are using the database driver and you have two domains sharing the same db, you should use two distinct queues if you want to manage the jobs of each domain separately.

For example, you could:

  • put in your .env files a default queue for each domain, e.g. QUEUE_DEFAULT=default1 for site1.com and QUEUE_DEFAULT=default2 for site2.com
  • update the queue.php config file by changing the default queue accordingly:
'database' => [
    'driver' => 'database',
    'table' => 'jobs',
    'queue' => env('QUEUE_DEFAULT','default'),
    'retry_after' => 90,
],
  • launch two distinct workers
 php artisan queue:work --domain=site1.com --queue=default1

and

 php artisan queue:work --domain=site1.com --queue=default2

Obviously, the same can be done for each other queue driver, apart from the sync driver.

storage:link command

If you make use of the storage:link command and you want a distinct symbolic link for each domain, you have to create them manually because to date such command always creates a link named storage and that name is hard coded in the command. Extending the storage:link command allowing to choose the name is outside the scope of this package (and I hope it will be done directly in future versions of Laravel).

A way to obtain multiple storage links could be the following. Let us suppose to have two domains, namely site1.com and site2.com with associated storage folders storage/site1_com and storage/site2_com.

  1. We manually create links for each domain:
ln -s storage/site1_com/app/public public/storage-site1_com 
ln -s storage/site2_com/app/public public/storage-site2_com 
  1. In .env.site1.com and .env.site2.com we add an entry, e.g., for the first domain:
APP_PUBLIC_STORAGE=-site1_com
  1. In the filesystems.php config file we change as follows:
'public' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => env('APP_URL').'/storage'.env('APP_PUBLIC_STORAGE'),
    'visibility' => 'public',
],

Furthermore, if you are using the package in a Single Page Application (SPA) setting, you could better handling distinct public resources for each domain via .htaccess or similar solutions as pointed out by Scaenicus in his .htaccess solution.

Storing environment files in a custom folder

Starting from version 1.1.11 a second argument has been added to the Application constructor in order to choose the folder where to place the environment files: if you have tens of domains, it is not very pleasant to have environment files in the root Laravel's app folder.

So, if you want to use a different folder simply add it at the very top of the bootstrap/app.php file. for example, if you want to add environment files to the envs subfolder, simply do:

//use Illuminate\Foundation\Application;
use Gecche\Multidomain\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

$environmentPath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'envs';

$domainParams = [];

return Application::configure(basePath: dirname(__DIR__),
    environmentPath: $environmentPath,
    domainParams: $domainParams)
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

If you do not specify the second argument, the standard folder is assumed. Please note that if you specify a folder, also the standard .env file has to be placed in it

Default environment files and storage folders

If you try to run a web page or an shell command under a certain domain, e.g. sub1.site1.com and there is no specific environment file for that domain, i.e. the file .env.sub1.site1.com does not exist, the package will use the first available environment file by splitting the domain name with dots. In this example, the package searches for the the first environment file among the followings:

.env.site1.com
.env.com
.env

The same logic applies to the storage folder as well.

About Laravel's Scheduler, Supervisor and some limitation

If in your setting you make use of the Laravel's Scheduler, remember that also the command schedule:run has to be launched with the domain option. Hence, you have to launch a scheduler for each domain. At first one could think that one Scheduler instance should handle the commands launched for any domain, but the Scheduler itself is run within a Laravel Application, so the "env" under which it is run, automatically applies to each scheduled command and the --domain option has no effect at all.

The same applies to externals tools like Supervisor: if you use Supervisor for artisan commands, e.g. the queue:work command, please be sure to prepare a command for each domain you want to handle.

Due to the above, there are some cases in which the package can't work: in those settings where you don't have the possibility of changing for example the supervisor configuration rather than the crontab entries for the scheduler. Such an example has been pointed out here in which a Docker instance has been used.

Lastly, be aware that some Laravel commands call other Artisan commands from the inside, obviously without the --domain option. The above situation does not work properly because the subcommand will work with the standard environment file. An example is the migrate command when using the --seed option.

laravel-multidomain's People

Contributors

ainars-good avatar deprecator avatar gecche avatar grummfy avatar leadegroot avatar mrspence avatar nimah79 avatar rhynodesigns avatar robertogallea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-multidomain's Issues

artisan config:cache --domain problem

Hello,
I'm using laravel 5.5.49, I've followed your installation instruction but when I do the command ex: "php artisan config:cache --domain=site2.com" it doesn't create the "config-site2_com.php" file in bootstrap/cache directory, so the "multi-domain" feature doesn't work and it read only 1 .env file (I suppose the default .env). Is there any way to fix it?

Can't link multiple stoarge for doamins.

Added this package to my project and its working fine. I need to link separate storage for each domains and it fails.
Uses this steps in Readme :

ln -s storage/site1_com/app/public public/storage-site1_com 
ln -s storage/site2_com/app/public public/storage-site2_com 

and shows the following error.

"ln : The term 'ln' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and 
try again. At line:1 char:1"

The path i used is correct too.. help pls..

solved laravel-passport problem but laravel-permission not yet

Hi,

We are creating a big crm / acaunting software that we wanted to prefer laravel-multidomain package for our project for run only one laravel installation with multi databases.

at the first install we have got an error with laravel-passport package, error was "Unable to read key" \vendor\league\oauth2-server\src\CryptKey.php:77

key

We can not find any quick solve subject on internet. After few try, it was very easy to solve with following cli command
php artisan passport:keys --domain=sub.domainname.com

we are using spatie/laravel-permission package for for controlling user roles.
many functions our software are seems working properly (for now) expect one,

passport

when we go to user edit function, we have got following error
BadMethodCallException Call to undefined method App\Models\User\User::getRoleIds() (View: /var/www/sub.domainname.com/html/resources/views/Panel/User/Edit.blade.php)

we are searching for a simple solution until find, i will be appricated if you suggest.

thanks in advance,
Kerim

Using public storage

Hi, I want to use the app/storage/{domain}/app/public folder to a favicon for each domain. What's the best way to access the this folder ...? In single domain I use symlink but not documented for your package.

Subdomain

Hi.

What about a subdomains like api.domain.com or *.domain.com? It's not working for configuration file with the name .env.domain.com.

Thanks.

New domain can’t be reached.

Hi,

I installed the package and added the following domain: "sub.laratest.test."(I want to use the package for multiple subdomains), but it's giving me the This site can’t be reached response.

I'm using Laragon on Windows which creates virtual hosts. For example I type "laratest.test" url instead of localhost/laratest.

Have you got any ideas?

Best Regards

Configuring routing

How to configure web.php so that it works according to the following scenario:
The database has a table with a list of domain names:
test.ru
The primary domain specified in .env test.kz
The list of domain names is dynamic, and so as not to specify each domain in the web.php, whether it is possible to somehow facilitate the task.

error run composer

help me please!
I can't run composer require gecche/laravel-multidomain
my computer run windown 10, xampp, apache, php 7.1
VirtualAlloc() failed: [0x00000008] Not enough memory resources are available to process this command.

Question: Multiple config

Hi,

I have for each website other config. Some websites they have another logo, some website they have a video box and some not.

All this config is to much to put it in the env file.

So i think its better that every domain has own config file (array).

Than in the blade/controller i want use config('site.var').

For now i have fix it by myself:

config/site.php

<?php
return include(config_path(domain_sanitized(app()->domain())) . '/site.php');

config/site1_com/site.php

<?php

return [
    'test' => 'Hello'
];

controller

<?php

namespace App\Http\Controllers;

class IndexController extends Controller
{
    public function index()
    {
        dump(config('site.test'));
    }
}

Maybe you have better idea?

Feature wish: artisan --all-domains option

Maybe I haven't read the documentation enough, but is there a way to do some artisan task for all domains?
Something like:

php artisan --all-domains cache:clear
php artisan --all-domains config:clear
php artisan --all-domains migrate --seed

If not I will probably develop a bash script which evaluates php artisan domain:list to repeat tasks for each domain.

Handle different APP_ENVs

Maybe I'm missing something but how can different APP_ENVs (local, staging, production) be handled?

I think it's not a problem to all required domains to domain.php but is this the right way to have 3 entries for 1 domain?

Bug: Queue is not compatible with newer versions of Illuminate\Queue

Hello there. We integrated your package with one of our projects and came across the follwing issue: running queue:listen command with --domain option doesn't work as expected. The QueueListen command signature is different from the newer versions so the option won't get passed to queue:work command. I have worked this issue out and here's the fix.

View and controller

Hello
I have a question or maybe two.
I don't understand how to give blade files (where I should put them) to the different domains and how to put the view in controller? With folder path?

Run Migrate and Seeder on new domain

Hi there,

I am really glad you created this package. It mostly solves all of my problems. But, let's say, I created a new domain tenant1.site.com.

How do I run the migrations and seeders on this tenant1 database?

I would really appreciate it If you could add some command to migrate to a new domain database.

like: php artisan domain:migrate tenant1

Thanks & Regards
Bilal Younas

Caching routes error

Running the following commands:

php artisan route:cache --domain=site1.com
php artisan route:cache --domain=site2.com
php artisan route:cache --domain=site3.com

will cause all 3 domains to use the site3.com routes.

Can you replicate that issue?

I think it's a schedule --domain dispatch bug.

* * * * * root php -d memory_limit=-1 /var/www/artisan schedule:run --domain=api.domain.com >/tmp/cron.last 2>&1

php /var/www/artisan queue:work --domain=api.domain.com --timeout=1800 --sleep=3 --tries=1

I run cron as an option,

$schedule->command('cleanPdfs', ['--thread'=>'queue'])->everyMinute()->timezone('Asia/Seoul');

The schedule reads like this:

    protected $signature = 'cleanPdfs {--thread=single}';

    protected $description = 'Command description';

    public function handle()
    {
         dispatch((new APICallCommandJob("sub1.domain.com", $command)));
    }

When the command in the schedule is executed like this,
Dispatch is normally registered in Job.

However, at the same time as dispatch job registration,
Like dispatch_now too run, and dispatch is too run

That is, once in the queue, once in the schedule php, a total of 2 runs.

to solve this

I should have used the env option in cron, not the domain option.

* * * * * root php -d memory_limit=-1 /var/www/artisan schedule:run --env=api.domain.com >/tmp/cron.last 2>&1
$schedule->command('cleanPdfs', ['--thread'=>'queue'])->everyMinute()->timezone('Asia/Seoul')->environments('api.domain.com');

I'm not sure where the problem is either, sorry.

Support for Laravel 8

Hi Giacomo,
Could you please add Laravel 8 support to your package?

Thank you!
Andrea

Run commands with the --domain option from another command

Hi, i'm trying to create the command domains:migrate in order to run the artisan migrate command on all domains.

My command handle function is as follows:

public function handle()
{
    $domains = config('domain.domains');

    foreach($domains as $domain) {
        $this->call('migrate', ['--domain' => $domain]);
    }

    return true;
}

When i run the command, i expect it to migrate to all 3 of my domains. But it fails and returns "nothing to migrate":

$ php artisan domains:migrate
Nothing to migrate.
Nothing to migrate.
Nothing to migrate.

How can i create a command to execute migration on all my domains?
Thanks

Wrong Log path from job dispatched

Hi, first thanks for this package. I'm making some tests and i found maybe an issue.

I'm connected on my site a. I write a log info from a http request, the log write into log file domain (storage/site_a/logs/laravel.log), all good.

But when i write a log inside a job and dispatch this job, the log write in storage/logs/laravel.log and not in storage/site_a/logs/laravel.log.

Any idea why ?

Opinion

I have an opinion, if it have a function domain:list to show completly list of domain on system. and saving domain list to database

domain:update_env Changes all env files even when domain option present


$data = '{"APP_URL":"site1.domain.local","APP_NAME":"Site 1 name","DB_DATABASE":"site1db"}';
Artisan::call("domain:update_env --domain='site1' --domain_values='".$data."'");

Hi !
Runing this code changes all .env files, even when the domain option present.

What's wrong with my code?

Domain parameter not defined with supervisor

Hi.

I use a Docker with worker container and supervisor in it. In worker config file I defined the command=/usr/local/bin/php /var/www/html/artisan queue:work --sleep=3 --tries=3 --domain=domain.com. The supervisor defined as ENTRYPOINT in Dockerfile (with worker config).
So in detectDomain method the argv parameter don't have the domain key. Therefore, the scheduler always uses the .env config file.

Any ideas?

Thanks.

Storing multiple `.env` files

Hey,

⭐Fantastic package! Does a lot of heavy-lifting that I didn't expect to find, thank-you OP :)

I've begun extending it a little further for my own needs, do you have any suggestions for how to store the .env.site.com files?

Currently I will have around ~100 .env.site.com files sat in the root directory, I'm wondering how it could be possible to move into a subfolder like env/... or something...

What are your thoughts?

Best,
Matt

Issue with ngnix wildcard sub domain

First of all thanks for the nice package.

When I try to use wildcard domain setup in ngnix like below

server_name ~^(?.+).domain.com$;

OR

server_name *.domain.com

The environment variable $_SERVER[SERVER_NAME] =&gt; ~^(?.+).domain.com$ is passed as this to php. As the package relying on $_SERVER[SERVER_NAME], it is not able to detect correct environment. But the $_SERVER[HTTP_HOST] is passed properly in this case.

Not sure it is an issue with the package or is there any work around to pass the server name properly from ngnix?

Thanks in advance.

Issue with storage link for multiple domains, saving to

Hi,
I uploaded an image file which saves into /storage/superlaravel_test/app/public/3/ - It's perfect.

But, when I preview the image, it shows me as => http://superlaravel.test/storage/superlaravel_test/3/file.png
"/app/public/" is missing in the generated link. I wonder why.

My .env.superlaravel_test file has
APP_PUBLIC_STORAGE=superlaravel_test ===> is this correct or should I add "/app/public/"

My filesystems.php has
'url' => env('APP_URL').'/storage'.'/'.env('APP_PUBLIC_STORAGE'), ====> should I add here?

What am I doing wrong?

Thank you for your time,

Regds,
newbie

Local and Server - should both domains exist in domain.php or environment-specific configuration

Hi,
I have added all .test domains for the local machine and it is working fine. Now I need to move the project to the server and I am wondering the best way to add live domains as I want to manage both local and production environment without disturbing the code.

So then do I need to add .env.livedomain.com in addition to already created .env.testdomain.test and also add domains in the config/domain.php.

Am I on the right path? If there's a configuration that is set for live and local that automatically gets switched based on the environment, that'll be great. Please share your inputs at your convenience.

Thanks
Newbie.

Domain specific migration and seeders

Hi, first of all, this is an amazing package, able to get it up and working.

I am a little puzzled with the migrations and seeding for specific DB/Domain. I created database/migrations/site_test folder to store site_test specific files. However, when I run the command "php artisan migrate --domain=site.test" - the system loads the migration tables from the migrations folder and not the site_test folder. Why this is happening?

Also, how do I run seeders for a specific domain? Do I have to create a subfolder sites_test under /seeders/ folder - just like /migrations/ - will that work?

Thank you for your help.

Regards

cant read .env on multisite

hi, i try to make a laravel apps with multi site and multi domain with different database in single code base. i try to config .env each site. but when i try to config:cache it still using one database. im using laravel 5.8

Issue with the www subdomain

Hi!
First of all, thank you for this package :)!

Description

I have an issue with my subdomain when use "www" subdomain.
Maybe it's a configuration issue but not sure, need help :).

Prerequisites

  • have mydomain.com configured
  • add mydomain.com with php artisan domain:add mydomain.com

Scenario

Observed result

Seems that DomainDetector is looking for a .env file using SERVER_NAME.
Then here .env.www.mydomain.com is waited but only .env.mydomain.com is existing.

Expected result

DomainDetector::detectWebDomain() should return domain name without www subdomain

I'm not aware of best practice of using or not the "www" subdomain. But would prefer to not rewriting the url in htaccess...

Regards.

Storage:link to Public

Hi there,

When I upload the file goes to storage/domain/app/public. I tried to create a symlink for this directory but it says. public/storage already exists for default linking.

I used php artisan storage:link --domain=domain-address

How do I create a symlink for each domain?
or
How do I use the default storage directory for all domains?

Regards,
Bilal Younas

Models

How should I use this tool if I have an application that shares the same database on all domains?

For example,

If i have this tables

Products
Settings
Menus

Would I need to add the domain as an id in each model and add a global scope to filter by domain?

Scheduled commands not dedecting the environment

@gecche, I have few commands scheduled in main scheduler Console\Kernel.php. When I run the scheduler with --domain option, the subsequent commands are not aware of the domain. I have to pass the --domain option to each command explicitly.

Ex:
php artisan schedule:run --domain=demo.mysite.com

I have another command scheduled as

$schedule->command("article:update-status")->hourly();
But this is not working. So I have to pass domain like below for each command.

$domain = app('domain');
$schedule->command("article:update-status --domain=$domain")->hourly();

Is this expected behaviour?

Public disk - How to handle properly?

Hello!

Thank you for you great tool!
How would
php artisan storage:link --domain domain.of.this.site
work properly?

https://laravel.com/docs/master/filesystem#the-public-disk

Currently I would manipulate the config/filesystem.php to point every request into the default storage/app/public/domain.of.this.site directory


That said, even cooler would be a file resolution trick to replace the public/storage directory with the correct one.

Which should be possible with .htaccess

What have you planned in that regard?

Queue

What about queue? Is it use .env.domain or default .env?
I need different MAIL_FROM_ADDRESS for domains.

Question: Jetstream

Hello
I am confused very much nowadays. So much to do within one laravel and not sure if jetstream will work without problem on different domains.
Did someone try laravel jetstream with laravel multidomain?
Does it working fine without problems or redirection is confusing for jetstream? Or something else can be the problem?

is it able to work with Octane?

Hey Folks,

I was able to put my project (which use laravel-multidomain) to work with octane (swoole), with no additional effort it is able to run cli commands.
But when I try from web looks like only use the original .env file no matter the domain I use. Any suggestion to solve it?

Thank in advance

Heroku Config Vars

Hi,
heroku.com only allows single config vars option from backend dashboard.

Is there any way to avoid using the .env.domain.com environment file?

In bootstrap/cache/config-domain.com; it would have been best if we can only set limitted variables and defaulting to values available from default values from .env file.

Issue with installing other packages with laravel-multidomain

I have installed laravel-multidomain and did all the configuration by following the document. After that I was trying to install package alexusmai/laravel-file-manager and getting following error

php artisan package:discover --ansi
In Container.php line 1017:
Target [Alexusmai\LaravelFileManager\Services\ConfigService\ConfigRepository] is not instantiable.

It works fine without laravel-multidomain.

Laravel version: 7.29.3

Using cron / scheduler properly

If I have 3 domains using the same app, I wonder if I should create three different cron jobs like that:

php artisan schedule:run --domain=site1.com
php artisan schedule:run --domain=site2.com
php artisan schedule:run --domain=site3.com

Or if I should create just one cron job like that:

php artisan schedule:run

Since the App\Console\Kernel.php is using use Gecche\Multidomain\Foundation\Console\Kernel as ConsoleKernel;

The reason I'm asking is because I want to run $schedule->command('horizon:snapshot')->everyFiveMinutes(); on the 3 domains (each domain has a php artisan horizon --domain=siteX.com set up.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.