Skip to content

Commit

Permalink
Added Scope WithUnpublishedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
roni-estein committed Jul 10, 2021
1 parent 755ab7c commit a31c1e7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function scopePublished($query)
{
return $query
->whereNotNull('published_at')
->whereDate('published_at','<=', now(Press::timezone()));
->whereDate('published_at', '<=', now(Press::timezone()));
}

/**
Expand All @@ -79,6 +79,21 @@ public function scopeUnpublished($query)
return $query->whereNull('published_at');
}

/**
* Scope a query to only include Published posts.
*
* @param Builder $query
*
* @return Builder
*/
public function scopeWithUnpublishedBy($query, $slug)
{
return $query->orWhereHas('authors', function ($query) use ($slug) {
return $query->where(Press::authorSlug(), $slug);
});
}


/**
* Scope a query to order posts by published at where they are published.
*
Expand Down

0 comments on commit a31c1e7

Please sign in to comment.