nimuli/app/Livewire/Modals/EditBioPage.php

71 lines
1.7 KiB
PHP

<?php
namespace App\Livewire\Modals;
use App\Domains\Bio\Models\BioPage;
use Illuminate\View\View;
use LivewireUI\Modal\ModalComponent;
class EditBioPage extends ModalComponent
{
public string $bioUlid = '';
public string $title = '';
public string $slug = '';
public bool $isPublished = false;
public function mount(string $bioUlid): void
{
$workspace = app('current_workspace');
$bio = BioPage::where('ulid', $bioUlid)
->where('workspace_id', $workspace->id)
->firstOrFail();
$this->bioUlid = $bioUlid;
$this->title = $bio->getTranslation('title', 'en') ?? '';
$this->slug = $bio->slug;
$this->isPublished = $bio->is_published;
}
protected function rules(): array
{
return [
'title' => 'required|max:200',
'slug' => 'nullable|alpha_dash|max:80',
'isPublished' => 'boolean',
];
}
public function save(): void
{
$this->validate();
$workspace = app('current_workspace');
$bio = BioPage::where('ulid', $this->bioUlid)
->where('workspace_id', $workspace->id)
->firstOrFail();
$bio->update([
'title' => ['en' => $this->title, 'de' => $this->title],
'slug' => $this->slug ?: $bio->slug,
'is_published' => $this->isPublished,
]);
$this->dispatch('bioPageUpdated', bioUlid: $this->bioUlid);
$this->dispatch('toast', message: 'Bio Page aktualisiert', type: 'success');
$this->closeModal();
}
public static function modalMaxWidth(): string
{
return 'md';
}
public function render(): View
{
return view('livewire.modals.edit-bio-page');
}
}