61 lines
2.2 KiB
PHP
Raw Normal View History

2023-05-25 17:27:52 +01:00
<?php
namespace App\Http\Livewire\Notifications;
use App\Models\Team;
use Livewire\Component;
class EmailSettings extends Component
{
2023-06-02 12:34:45 +02:00
public Team $model;
2023-05-25 17:27:52 +01:00
protected $rules = [
2023-06-01 13:24:20 +02:00
'model.extra_attributes.smtp_active' => 'nullable|boolean',
2023-06-06 17:50:13 +02:00
'model.extra_attributes.smtp_from_address' => 'required|email',
'model.extra_attributes.smtp_from_name' => 'required',
'model.extra_attributes.smtp_recipients' => 'required',
2023-06-01 13:24:20 +02:00
'model.extra_attributes.smtp_host' => 'required',
'model.extra_attributes.smtp_port' => 'required',
'model.extra_attributes.smtp_encryption' => 'nullable',
'model.extra_attributes.smtp_username' => 'nullable',
'model.extra_attributes.smtp_password' => 'nullable',
'model.extra_attributes.smtp_timeout' => 'nullable',
2023-06-06 17:50:13 +02:00
'model.extra_attributes.smtp_test_recipients' => 'nullable',
2023-05-25 17:27:52 +01:00
];
protected $validationAttributes = [
2023-06-06 17:50:13 +02:00
'model.extra_attributes.smtp_from_address' => '',
'model.extra_attributes.smtp_from_name' => '',
'model.extra_attributes.smtp_recipients' => '',
2023-06-01 13:54:38 +02:00
'model.extra_attributes.smtp_host' => '',
'model.extra_attributes.smtp_port' => '',
'model.extra_attributes.smtp_encryption' => '',
'model.extra_attributes.smtp_username' => '',
'model.extra_attributes.smtp_password' => '',
2023-06-06 17:50:13 +02:00
'model.extra_attributes.smtp_test_recipients' => '',
2023-05-25 17:27:52 +01:00
];
public function submit()
{
$this->resetErrorBag();
$this->validate();
2023-06-06 17:50:13 +02:00
$this->model->extra_attributes->smtp_recipients = str_replace(' ', '', $this->model->extra_attributes->smtp_recipients);
$this->model->extra_attributes->smtp_test_recipients = str_replace(' ', '', $this->model->extra_attributes->smtp_test_recipients);
2023-06-01 12:15:33 +02:00
$this->saveModel();
}
private function saveModel()
{
2023-05-25 17:27:52 +01:00
$this->model->save();
2023-06-01 12:15:33 +02:00
if (is_a($this->model, Team::class)) {
2023-05-25 17:27:52 +01:00
session(['currentTeam' => $this->model]);
}
}
2023-06-01 12:15:33 +02:00
public function instantSave()
2023-05-25 17:27:52 +01:00
{
2023-06-01 13:24:20 +02:00
try {
$this->submit();
} catch (\Exception $e) {
$this->model->extra_attributes->smtp_active = false;
$this->validate();
}
2023-05-25 17:27:52 +01:00
}
}