diff --git a/app/Http/Controllers/Guest/TagController.php b/app/Http/Controllers/Guest/TagController.php index 89fb929f9..f27fa07f0 100644 --- a/app/Http/Controllers/Guest/TagController.php +++ b/app/Http/Controllers/Guest/TagController.php @@ -28,8 +28,13 @@ public function index(Request $request): View $tags = Tag::publicOnly() ->withCount(['links' => fn($query) => $query->publicOnly()]) - ->orderBy($this->orderBy, $this->orderDir) - ->paginate(getPaginationLimit()); + ->orderBy($this->orderBy, $this->orderDir); + + if ($request->input('filter')) { + $tags = $tags->where('name', 'like', '%' . $request->input('filter') . '%'); + } + + $tags = $tags->paginate(getPaginationLimit()); return view('guest.tags.index', [ 'pageTitle' => trans('tag.tags'), diff --git a/resources/views/guest/tags/index.blade.php b/resources/views/guest/tags/index.blade.php index 8b97ea494..ace9c8cee 100644 --- a/resources/views/guest/tags/index.blade.php +++ b/resources/views/guest/tags/index.blade.php @@ -10,10 +10,28 @@

@lang('tag.tags')

- - - @lang('linkace.feed') - +
+
+
+ +
+ + + + + +
+
+ + + @lang('linkace.feed') + +
+
diff --git a/tests/Controller/Guest/TagControllerTest.php b/tests/Controller/Guest/TagControllerTest.php index 7b1a3b099..73bfc0c68 100644 --- a/tests/Controller/Guest/TagControllerTest.php +++ b/tests/Controller/Guest/TagControllerTest.php @@ -67,4 +67,22 @@ public function test_invalid_tag_detail_response(): void $this->get('guest/tags/1')->assertNotFound(); $this->get('guest/tags/myTag')->assertNotFound(); } + + public function test_tag_search(): void + { + User::factory()->create(); + Tag::factory()->create([ + 'name' => 'testTag1', + 'visibility' => 1, + ]); + Tag::factory()->create([ + 'name' => 'testTag2', + 'visibility' => 1, + ]); + $this->get('guest/tags?filter=testTag1')->assertSee('testTag1') + ->assertDontSee('testTag2'); + + $this->get('guest/tags?filter=testTag2')->assertSee('testTag2') + ->assertDontSee('testTag1'); + } }