lasthourcloud/app/Http/Livewire/Notifications/DiscordSettings.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2023-05-25 16:27:52 +00:00
<?php
namespace App\Http\Livewire\Notifications;
use App\Models\Server;
use App\Models\Team;
2023-06-14 09:54:00 +00:00
use App\Notifications\Notifications\TestNotification;
2023-05-25 16:27:52 +00:00
use Illuminate\Support\Facades\Notification;
use Livewire\Component;
class DiscordSettings extends Component
{
2023-06-02 10:34:45 +00:00
public Team $model;
2023-05-25 16:27:52 +00:00
protected $rules = [
2023-06-01 11:24:20 +00:00
'model.extra_attributes.discord_active' => 'nullable|boolean',
'model.extra_attributes.discord_webhook' => 'required|url',
2023-05-25 16:27:52 +00:00
];
protected $validationAttributes = [
2023-06-07 15:24:37 +00:00
'model.extra_attributes.discord_webhook' => 'Discord Webhook',
2023-05-25 16:27:52 +00:00
];
2023-06-02 10:34:45 +00:00
2023-06-01 10:15:33 +00:00
public function instantSave()
{
try {
$this->submit();
} catch (\Exception $e) {
2023-06-01 11:24:20 +00:00
$this->model->extra_attributes->discord_active = false;
$this->validate();
2023-06-01 10:15:33 +00:00
}
}
private function saveModel()
2023-05-25 16:27:52 +00:00
{
$this->model->save();
2023-06-01 10:15:33 +00:00
if (is_a($this->model, Team::class)) {
2023-05-25 16:27:52 +00:00
session(['currentTeam' => $this->model]);
}
}
2023-06-01 10:15:33 +00:00
public function submit()
2023-05-25 16:27:52 +00:00
{
2023-06-01 10:15:33 +00:00
$this->resetErrorBag();
$this->validate();
$this->saveModel();
2023-05-25 16:27:52 +00:00
}
2023-06-01 10:15:33 +00:00
public function sendTestNotification()
2023-05-25 16:27:52 +00:00
{
2023-06-01 10:15:33 +00:00
Notification::send($this->model, new TestNotification);
2023-05-25 16:27:52 +00:00
}
}