Refactor mail-sender

This commit is contained in:
yogesh-gohil
2023-03-17 18:54:58 +05:30
parent aececb8575
commit dea73bcdf8
10 changed files with 99 additions and 67 deletions

View File

@ -59,6 +59,10 @@ class MailSender extends Model
{
$senderMail = self::create($request->getMailSenderPayload());
if ($request->is_default) {
$senderMail->removeOtherDefaultMailSenders($request);
}
return $senderMail;
}
@ -68,6 +72,10 @@ class MailSender extends Model
$this->update($data);
if ($request->is_default) {
$this->removeOtherDefaultMailSenders($request);
}
return $this;
}
@ -81,6 +89,9 @@ class MailSender extends Model
'address' => $mailSender->from_address,
'name' => $mailSender->from_name
];
$settings['sendmail'] = config('mail.sendmail');
$settings['markdown'] = config('mail.markdown');
$settings['log_channel'] = config('mail.log_channel');
Config::set('mail', $settings);
@ -91,4 +102,10 @@ class MailSender extends Model
return true;
}
public function removeOtherDefaultMailSenders($request) {
MailSender::where('company_id', $request->header('company'))
->where('is_default', true)
->where('id', '<>', $this->id)
->update(['is_default' => false]);
}
}