multi-tenant icon indicating copy to clipboard operation
multi-tenant copied to clipboard

Mail configuration file for each tenant

Open pcodetm opened this issue 5 years ago • 3 comments

Hello, how can I configure the sending of mail for each of the tenants? That each tenant manages its own mail configuration file

pcodetm avatar Oct 22 '20 21:10 pcodetm

You would build all that into your app's code at the tenant layer. Essentially:

  • in your app build some sort of way to store configuration settings unique to each tenant
  • then retrieve and set the configuration whenever the tenant is activated

This would likely include things like:

  • tenant-side migrations, models, etc for storing configuration settings records in the tenant's database
  • maybe create a ConfigServiceProvider to read all the config settings from the db and add them into Laravel's configuration registry with the config() helper or Config facade
  • alternatively maybe listen for the tenant Switched event (see the docs) and swap settings at that point

drbyte avatar Oct 22 '20 23:10 drbyte

Hello thanks for the valuable help. Configure the application as indicated

  1. I have created the ConfigServiceProvider class and within the method I call my ConfigurationMailServer class that contains the configuration for sending emails.

image

  1. Register provider image

Once all the configuration is done I receive a message in the console when I execute the following command:

$ php artisan config: cache

image

pcodetm avatar Oct 23 '20 21:10 pcodetm

I faced a similar problem recently. Instead of using a Service Provider, use a Middleware. For some reason, the boot method on the Sevice Provider runs before a tenant has been identified. So use a middleware but make sure it is not global middleware on Kernel because it will run on every request. Assign that middleware to only one route that is going to trigger that email sending.

richardkeep avatar Nov 02 '20 06:11 richardkeep