diff --git a/app/Http/Controllers/DeletionController.php b/app/Http/Controllers/DeletionController.php index eb9929e..0adadf1 100644 --- a/app/Http/Controllers/DeletionController.php +++ b/app/Http/Controllers/DeletionController.php @@ -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'); + } } diff --git a/app/Livewire/App/DataCard.php b/app/Livewire/App/DataCard.php new file mode 100644 index 0000000..3d6c133 --- /dev/null +++ b/app/Livewire/App/DataCard.php @@ -0,0 +1,17 @@ + TagGroup::all()]); + } + + public function create() + { + $this->validate(); + + TagGroup::create([ + 'name' => $this->name, + 'color' => $this->color, + 'description' => $this->description, + ]); + + return $this->redirectRoute('tags.groups'); + } +} diff --git a/app/Livewire/Tags/Index.php b/app/Livewire/Tags/Index.php new file mode 100644 index 0000000..304bb7d --- /dev/null +++ b/app/Livewire/Tags/Index.php @@ -0,0 +1,53 @@ +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'); + } +} diff --git a/app/Models/Tag.php b/app/Models/Tag.php index c48f54e..1e37bfb 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -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); + } } diff --git a/app/Models/TagGroup.php b/app/Models/TagGroup.php new file mode 100644 index 0000000..60d8fa4 --- /dev/null +++ b/app/Models/TagGroup.php @@ -0,0 +1,16 @@ +hasMany(Tag::class); + } +} diff --git a/database/migrations/2025_05_21_173221_create_tags_table.php b/database/migrations/2025_05_21_173221_create_tags_table.php index 85f6a52..42b3272 100644 --- a/database/migrations/2025_05_21_173221_create_tags_table.php +++ b/database/migrations/2025_05_21_173221_create_tags_table.php @@ -13,6 +13,8 @@ return new class extends Migration { Schema::create('tags', function (Blueprint $table) { $table->id(); + $table->string('name'); + $table->string('slug')->unique(); $table->timestamps(); }); } diff --git a/database/migrations/2025_05_24_233254_create_tag_groups_table.php b/database/migrations/2025_05_24_233254_create_tag_groups_table.php new file mode 100644 index 0000000..fc784ef --- /dev/null +++ b/database/migrations/2025_05_24_233254_create_tag_groups_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('name'); + $table->string('color'); + $table->string('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('tag_groups'); + } +}; diff --git a/resources/views/livewire/app/data-card.blade.php b/resources/views/livewire/app/data-card.blade.php new file mode 100644 index 0000000..2a07241 --- /dev/null +++ b/resources/views/livewire/app/data-card.blade.php @@ -0,0 +1,11 @@ + +
+ + + + +
+
diff --git a/resources/views/livewire/app/navbar.blade.php b/resources/views/livewire/app/navbar.blade.php index 039ecf5..564212a 100644 --- a/resources/views/livewire/app/navbar.blade.php +++ b/resources/views/livewire/app/navbar.blade.php @@ -19,7 +19,7 @@ Upload - + Tags diff --git a/resources/views/livewire/pages/profile.blade.php b/resources/views/livewire/pages/profile.blade.php index e312339..458705a 100644 --- a/resources/views/livewire/pages/profile.blade.php +++ b/resources/views/livewire/pages/profile.blade.php @@ -1,25 +1,8 @@

{{ $user->name }}

- diff --git a/resources/views/livewire/posts/edit.blade.php b/resources/views/livewire/posts/edit.blade.php index 8094373..a36c87e 100644 --- a/resources/views/livewire/posts/edit.blade.php +++ b/resources/views/livewire/posts/edit.blade.php @@ -8,7 +8,7 @@ Changes are automatically saved. -