diff --git a/readme.md b/readme.md index 81bd90c4..ff4b0cc0 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ php artisan wink:install php artisan storage:link ``` -**Configure the database connection** wink is going to be using in `config/wink.php`. The run: +**Configure the database connection** wink is going to be using in `config/wink.php`. Then run: ```sh php artisan wink:migrate diff --git a/src/WinkPost.php b/src/WinkPost.php index f8689ab2..c5d32f25 100644 --- a/src/WinkPost.php +++ b/src/WinkPost.php @@ -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. *