Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail configuration file for each tenant #965

Open
pcodetm opened this issue Oct 22, 2020 · 3 comments
Open

Mail configuration file for each tenant #965

pcodetm opened this issue Oct 22, 2020 · 3 comments

Comments

@pcodetm
Copy link

pcodetm commented Oct 22, 2020

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

@drbyte
Copy link
Contributor

drbyte commented Oct 22, 2020

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

@pcodetm
Copy link
Author

pcodetm commented Oct 23, 2020

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

@richardkeep
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants