Skip to content

Commit 4f653ee

Browse files
authored
Merge pull request #273 from assertchris/feature/allow-filter-posts-by-tag-slug
Allow filter posts by tag (slug)
2 parents 60715c0 + 0b22814 commit 4f653ee

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/WinkPost.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ public function scopeAfterPublishDate($query, $date)
169169
return $query->where('publish_date', '>', $date);
170170
}
171171

172+
/**
173+
* Scope a query to only include posts that have a specific tag (by slug).
174+
*
175+
* @param \Illuminate\Database\Eloquent\Builder $query
176+
* @param string $slug
177+
* @return \Illuminate\Database\Eloquent\Builder
178+
*/
179+
public function scopeTag($query, string $slug)
180+
{
181+
return $query->whereHas('tags', function ($query) use ($slug) {
182+
$query->where('slug', $slug);
183+
});
184+
}
185+
172186
/**
173187
* Prepare a date for array / JSON serialization.
174188
*

0 commit comments

Comments
 (0)