lasthourcloud/app/Livewire/Project/Application/Preview/Form.php

55 lines
1.5 KiB
PHP
Raw Normal View History

2023-05-30 13:52:17 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Application\Preview;
2023-05-30 13:52:17 +00:00
use App\Models\Application;
use Livewire\Component;
use Spatie\Url\Url;
class Form extends Component
{
public Application $application;
2024-06-10 20:43:34 +00:00
2023-05-30 13:52:17 +00:00
public string $preview_url_template;
2024-06-10 20:43:34 +00:00
2023-05-30 13:52:17 +00:00
protected $rules = [
'application.preview_url_template' => 'required',
];
2024-06-10 20:43:34 +00:00
2023-06-16 10:35:40 +00:00
protected $validationAttributes = [
'application.preview_url_template' => 'preview url template',
];
2023-05-30 13:52:17 +00:00
public function resetToDefault()
{
$this->application->preview_url_template = '{{pr_id}}.{{domain}}';
$this->preview_url_template = $this->application->preview_url_template;
$this->application->save();
$this->generate_real_url();
}
2023-05-30 13:52:17 +00:00
public function generate_real_url()
{
if (data_get($this->application, 'fqdn')) {
$firstFqdn = str($this->application->fqdn)->before(',');
$url = Url::fromString($firstFqdn);
2023-05-30 13:52:17 +00:00
$host = $url->getHost();
$this->preview_url_template = str($this->application->preview_url_template)->replace('{{domain}}', $host);
2023-05-30 13:52:17 +00:00
}
}
2023-05-30 13:52:17 +00:00
public function mount()
{
$this->generate_real_url();
}
2023-05-30 13:52:17 +00:00
public function submit()
{
$this->validate();
$this->application->preview_url_template = str_replace(' ', '', $this->application->preview_url_template);
$this->application->save();
2024-02-22 13:53:42 +00:00
$this->dispatch('success', 'Preview url template updated.');
2023-05-30 13:52:17 +00:00
$this->generate_real_url();
}
}