nimuli/app/Livewire/Modals/CreateBioPage.php

56 lines
1.3 KiB
PHP

<?php
namespace App\Livewire\Modals;
use App\Domains\Bio\Models\BioPage;
use Illuminate\Support\Str;
use Illuminate\View\View;
use LivewireUI\Modal\ModalComponent;
class CreateBioPage extends ModalComponent
{
public string $title = '';
public string $slug = '';
protected function rules(): array
{
return [
'title' => 'required|max:200',
'slug' => 'nullable|alpha_dash|max:80|unique:bio_pages,slug',
];
}
public function save(): void
{
$this->validate();
$workspace = app('current_workspace');
if (empty($this->slug)) {
$this->slug = Str::slug($this->title).'-'.Str::random(4);
}
BioPage::create([
'workspace_id' => $workspace->id,
'slug' => $this->slug,
'title' => ['en' => $this->title, 'de' => $this->title],
'theme' => [],
'is_published' => false,
]);
$this->dispatch('bioPageCreated');
$this->dispatch('toast', message: 'Bio Page erstellt', type: 'success');
$this->closeModal();
}
public static function modalMaxWidth(): string
{
return 'md';
}
public function render(): View
{
return view('livewire.modals.create-bio-page');
}
}