How to make a dynamic shift post driver?

The user should select with the help of a service to send mail. For example, there are two drivers written by our own and Amazon SES. How you can handle this in the code that the driver has varied, depending on the user's choice?
April 7th 20 at 15:24
4 answers
April 7th 20 at 15:26
Solution
Went Laravel 7.0, and in the box appeared Multiple Mail Drivers
April 7th 20 at 15:28
How to make
As it is written in https://laravel.com/docs/6.x/configuration
The problem is that the driver is registered in advance - Jamie.Reich commented on April 7th 20 at 15:31
@Amalia32, and? - Loy.Altenwerth commented on April 7th 20 at 15:34
I can certainly write a separate driver that will handle this situation. But is it possible there are other solutions to this problem - Jamie.Reich commented on April 7th 20 at 15:37
@Amalia32kind of situation? - Loy.Altenwerth commented on April 7th 20 at 15:40
@terence_Murazik, In a situation, for example, when running the queue. If I by hand change the driver, it remains to work the old driver. - Jamie.Reich commented on April 7th 20 at 15:43
@Amalia32, well if you do it in the config file by hand to change, it, of course. Do you read prilinkovan section of the documentation? - Loy.Altenwerth commented on April 7th 20 at 15:46
@terence_Murazik, and If so to use, it still goes in the initialized driver
config(['mail.driver' => 'log']) - Jamie.Reich commented on April 7th 20 at 15:49
@Amalia32, bistromd:
$callback = Container::getInstance()->factory('mailer');
unset(Container::getInstance()['mailer']);
\config(['mail.driver' => 'log']);
Container::getInstance()->singleton('mailer', $callback);
- Loy.Altenwerth commented on April 7th 20 at 15:52
April 7th 20 at 15:30
By and large the user absolutely do not care what service the email is sent. I think so.
April 7th 20 at 15:32
I suggest you do your drivers as system components, adding a new driver wrap it in a class wrapper, all the necessary classes to cling to the application itself, and cause the one that will fit in the right situation, at the link you will find all the necessary information.
In addition, you can make intialization component only when they are called, i.e. when starting the application, they will not be initialized, but only in the time of the call.

Find more questions by tags Laravel