Add tag & tag group creation

This commit is contained in:
yuriko 🦊 2025-05-24 21:35:29 -04:00
parent f64afa649a
commit f2950ec7eb
15 changed files with 330 additions and 22 deletions

View file

@ -0,0 +1,17 @@
<?php
namespace App\Livewire\App;
use Livewire\Component;
class DataCard extends Component
{
public string $icon = 'question-mark';
public string $title = '';
public int $value = 0;
public function render()
{
return view('livewire.app.data-card');
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace App\Livewire\Tags;
use App\Models\TagGroup;
use Livewire\Attributes\Title;
use Livewire\Attributes\Validate;
use Livewire\Component;
class Groups extends Component
{
#[Validate('required|string|min:2|max:100|unique:tag_groups,name')]
public string $name = '';
#[Validate('required')]
public string $color = '';
#[Validate('nullable|string|max:240')]
public string $description = '';
#[Title("Tag groups")]
public function render()
{
return view('livewire.tags.groups', ['groups' => TagGroup::all()]);
}
public function create()
{
$this->validate();
TagGroup::create([
'name' => $this->name,
'color' => $this->color,
'description' => $this->description,
]);
return $this->redirectRoute('tags.groups');
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace App\Livewire\Tags;
use App\Models\Post;
use App\Models\Tag;
use App\Models\TagGroup;
use Illuminate\Support\Str;
use Livewire\Attributes\Title;
use Livewire\Attributes\Validate;
use Livewire\Component;
use MongoDB\Collection;
class Index extends Component
{
#[Validate('required|string|min:2|max:100|unique:tags,name')]
public string $name = '';
#[Validate('required|exists:tag_groups,id')]
public string $group = '';
#[Validate('nullable')]
public $implies = [];
public $untaggedPosts = [];
#[Title("Tags")]
public function render()
{
$this->untaggedPosts = Post::doesntHave('tags')->get();
return view('livewire.tags.index', [
'tags' => Tag::all(),
'tagGroups' => TagGroup::all(),
]);
}
public function create()
{
$this->validate();
$tag = Tag::create([
'name' => $this->name,
'slug' => Str::slug($this->name, '_'),
'implies' => $this->implies,
]);
$group = TagGroup::find($this->group);
$group->tags()->save($tag);
return $this->redirect('/tags');
}
}