Skip to content

Commit

Permalink
Merge pull request #273 from assertchris/feature/allow-filter-posts-b…
Browse files Browse the repository at this point in the history
…y-tag-slug

Allow filter posts by tag (slug)
  • Loading branch information
themsaid authored Aug 11, 2020
2 parents 60715c0 + 0b22814 commit 4f653ee
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/WinkPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ public function scopeAfterPublishDate($query, $date)
return $query->where('publish_date', '>', $date);
}

/**
* Scope a query to only include posts that have a specific tag (by slug).
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $slug
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTag($query, string $slug)
{
return $query->whereHas('tags', function ($query) use ($slug) {
$query->where('slug', $slug);
});
}

/**
* Prepare a date for array / JSON serialization.
*
Expand Down

0 comments on commit 4f653ee

Please sign in to comment.