DynamicMailConfig.php 689 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<?php

namespace App\Mailer;

use App\Models\Sender;
use Illuminate\Support\Facades\Config;
use Swift_SmtpTransport;
use Illuminate\Support\Facades\Mail;

class DynamicMailConfig
{
    public static function setConfig()
    {
        $email = DynamicMailConfig::getEmailSender();

        Config::set('mail.mailers.smtp.username', $email->address);
        Config::set('mail.mailers.smtp.password', $email->password);
    }

    public static function getEmailSender()
    {
        $email = Sender::query()->orderBy('count', 'asc')->first();

        $count = $email->count + 1;

        $email->update([
                    'count' => $count,
        ]);

        return $email;
    }
}