mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-09 21:42:57 +00:00
Add tag & tag group creation
This commit is contained in:
parent
f64afa649a
commit
f2950ec7eb
15 changed files with 330 additions and 22 deletions
|
|
@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\Comment;
|
||||
use App\Models\Post;
|
||||
use App\Models\Tag;
|
||||
use App\Models\TagGroup;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
|
@ -28,4 +30,20 @@ class DeletionController extends Controller
|
|||
$post->delete();
|
||||
return redirect()->route('posts.home');
|
||||
}
|
||||
|
||||
public function deleteTag(Tag $tag)
|
||||
{
|
||||
$tag->delete();
|
||||
return redirect()->route('tags.home');
|
||||
}
|
||||
|
||||
public function deleteTagGroup(TagGroup $tagGroup)
|
||||
{
|
||||
foreach ($tagGroup->tags as $tag)
|
||||
{
|
||||
$tag->delete();
|
||||
}
|
||||
$tagGroup->delete();
|
||||
return redirect()->route('tags.groups');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
app/Livewire/App/DataCard.php
Normal file
17
app/Livewire/App/DataCard.php
Normal 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');
|
||||
}
|
||||
}
|
||||
39
app/Livewire/Tags/Groups.php
Normal file
39
app/Livewire/Tags/Groups.php
Normal 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');
|
||||
}
|
||||
}
|
||||
53
app/Livewire/Tags/Index.php
Normal file
53
app/Livewire/Tags/Index.php
Normal 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');
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,10 @@
|
|||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use MongoDB\Laravel\Relations\BelongsTo;
|
||||
use MongoDB\Laravel\Relations\BelongsToMany;
|
||||
use MongoDB\Laravel\Relations\HasMany;
|
||||
use MongoDB\Laravel\Relations\MorphToMany;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
|
|
@ -13,4 +16,9 @@ class Tag extends Model
|
|||
{
|
||||
return $this->belongsToMany(Post::class);
|
||||
}
|
||||
|
||||
public function tagGroup(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TagGroup::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
app/Models/TagGroup.php
Normal file
16
app/Models/TagGroup.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use MongoDB\Laravel\Relations\HasMany;
|
||||
|
||||
class TagGroup extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'color', 'description'];
|
||||
|
||||
public function tags(): HasMany
|
||||
{
|
||||
return $this->hasMany(Tag::class);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue