Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #26 from ericvanjohnson/fix-blog-post-sort
Browse files Browse the repository at this point in the history
Suggestion to sort Blog Post by published_at
  • Loading branch information
Matt Lantz committed Oct 26, 2016
2 parents d356b07 + bd6ddef commit 031c5fa
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Repositories/BlogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ class BlogRepository
*/
public function all()
{
return Blog::orderBy('created_at', 'desc')->all();
return Blog::orderBy('published_at', 'desc')->all();
}

public function paginated()
{
return Blog::orderBy('created_at', 'desc')->paginate(Config::get('quarx.pagination', 25));
return Blog::orderBy('published_at', 'desc')->paginate(Config::get('quarx.pagination', 25));
}

public function publishedAndPaginated()
{
return Blog::orderBy('created_at', 'desc')->where('is_published', 1)->where('published_at', '<=', Carbon::now()->format('Y-m-d h:i:s'))->paginate(Config::get('quarx.pagination', 25));
return Blog::orderBy('published_at', 'desc')->where('is_published', 1)->where('published_at', '<=',
Carbon::now()->format('Y-m-d h:i:s'))->paginate(Config::get('quarx.pagination', 25));
}

public function published()
Expand All @@ -42,8 +43,8 @@ public function tags($tag)

public function allTags()
{
$tags = [];
$blogs = Blog::orderBy('created_at', 'desc')->get();
$tags = [];
$blogs = Blog::orderBy('published_at', 'desc')->get();

foreach ($blogs as $blog) {
foreach (explode(',', $blog->tags) as $tag) {
Expand All @@ -56,7 +57,7 @@ public function allTags()

public function search($input)
{
$query = Blog::orderBy('created_at', 'desc');
$query = Blog::orderBy('published_at', 'desc');
$query->where('id', 'LIKE', '%'.$input['term'].'%');

$columns = Schema::getColumnListing('blogs');
Expand Down

0 comments on commit 031c5fa

Please sign in to comment.