snipe-it/app/Http/Livewire/SlackSettingsForm.php

55 lines
1.5 KiB
PHP
Raw Normal View History

2023-01-24 09:25:05 -08:00
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Setting;
use App\Http\Controllers\Api\SettingsController;
2023-01-24 09:25:05 -08:00
class SlackSettingsForm extends Component
{
public $slack_endpoint;
public $slack_channel;
public $slack_botname;
2023-01-24 09:25:05 -08:00
public Setting $setting;
public function mount(){
2023-01-25 16:38:08 -08:00
$this->setting = Setting::getSettings();
$this->slack_endpoint = $this->setting->slack_endpoint;
$this->slack_channel = $this->setting->slack_channel;
$this->slack_botname = $this->setting->slack_botname;
}
2023-01-24 09:25:05 -08:00
public function render()
{
return view('livewire.slack-settings-form');
}
public function testSlack($slack_endpoint, $slack_channel, $slack_botname){
SettingsController::testSlack($slack_endpoint,$slack_channel,$slack_botname);
}
public function submit()
{
$this->validate([
'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable',
'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',
'slack_botname' => 'string|nullable',
]);
$this->setting->slack_endpoint = $this->slack_endpoint;
$this->setting->slack_channel = $this->slack_channel;
$this->setting->slack_botname = $this->slack_botname;
2023-01-31 11:32:05 -08:00
$this->setting->save();
session()->flash('message',trans('admin/settings/message.update.success'));
}
2023-01-24 09:25:05 -08:00
}