Skip to content

Commit

Permalink
Enhancement: Multi-Tag Filtering and Search Functionality (#1367)
Browse files Browse the repository at this point in the history
* Implement functionality to allow filtering based on multiple tags

* Fix styleci

* Update src/Storage/EntryModel.php

Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Update src/Storage/EntryModel.php

Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Update src/Storage/EntryModel.php

Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
3 people authored Aug 7, 2023
1 parent ccf937d commit 095cd0e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Storage/EntryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,17 @@ protected function whereBatchId($query, EntryQueryOptions $options)
protected function whereTag($query, EntryQueryOptions $options)
{
$query->when($options->tag, function ($query, $tag) {
return $query->whereIn('uuid', function ($query) use ($tag) {
$query->select('entry_uuid')->from('telescope_entries_tags')->whereTag($tag);
$tags = collect(explode(',', $tag))->map(fn ($tag) => trim($tag));

if ($tags->isEmpty()) {
return $query;
}

return $query->whereIn('uuid', function ($query) use ($tags) {
$query->select('entry_uuid')->from('telescope_entries_tags')
->whereIn('entry_uuid', function ($query) use ($tags) {
$query->select('entry_uuid')->from('telescope_entries_tags')->whereIn('tag', $tags->all());
});
});
});

Expand Down

0 comments on commit 095cd0e

Please sign in to comment.