74 lines
1.9 KiB
PHP
74 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use App\Domains\Link\Models\Link;
|
|
use Illuminate\View\View;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class EditLink extends ModalComponent
|
|
{
|
|
public string $linkUlid = '';
|
|
|
|
public int $linkId = 0;
|
|
|
|
public string $targetUrl = '';
|
|
|
|
public string $slug = '';
|
|
|
|
public string $title = '';
|
|
|
|
public string $status = 'active';
|
|
|
|
public function mount(string $linkUlid): void
|
|
{
|
|
$workspace = app('current_workspace');
|
|
$link = Link::where('ulid', $linkUlid)
|
|
->where('workspace_id', $workspace->id)
|
|
->firstOrFail();
|
|
|
|
$this->linkUlid = $linkUlid;
|
|
$this->linkId = $link->id;
|
|
$this->targetUrl = $link->target_url;
|
|
$this->slug = $link->slug;
|
|
$this->title = $link->title ?? '';
|
|
$this->status = $link->status;
|
|
}
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'targetUrl' => 'required|url|max:2048',
|
|
'slug' => 'required|alpha_dash|max:50|unique:links,slug,'.$this->linkId,
|
|
'title' => 'nullable|max:200',
|
|
'status' => 'required|in:active,inactive',
|
|
];
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$this->validate();
|
|
$workspace = app('current_workspace');
|
|
|
|
$link = Link::where('ulid', $this->linkUlid)
|
|
->where('workspace_id', $workspace->id)
|
|
->firstOrFail();
|
|
|
|
$link->update([
|
|
'target_url' => $this->targetUrl,
|
|
'slug' => $this->slug,
|
|
'title' => $this->title ?: null,
|
|
'status' => $this->status,
|
|
]);
|
|
|
|
$this->dispatch('linkUpdated', linkUlid: $this->linkUlid);
|
|
$this->dispatch('toast', message: 'Link aktualisiert', type: 'success');
|
|
$this->closeModal();
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.modals.edit-link');
|
|
}
|
|
}
|