Added limit to books shown on homepage and make alphabetical

This commit is contained in:
Dan Brown 2015-11-09 20:39:06 +00:00
parent e5b9be2e76
commit 76eb8fc5d7
3 changed files with 6 additions and 3 deletions

View File

@ -36,7 +36,7 @@ class HomeController extends Controller
*/ */
public function index() public function index()
{ {
$books = $this->bookRepo->getAll(); $books = $this->bookRepo->getAll(10);
$activity = $this->activityService->latest(); $activity = $this->activityService->latest();
return view('home', ['books' => $books, 'activity' => $activity]); return view('home', ['books' => $books, 'activity' => $activity]);
} }

View File

@ -25,9 +25,9 @@ class BookRepo
return $this->book->findOrFail($id); return $this->book->findOrFail($id);
} }
public function getAll() public function getAll($count = 10)
{ {
return $this->book->all(); return $this->book->orderBy('name', 'asc')->take($count)->get();
} }
/** /**

View File

@ -11,6 +11,9 @@
@include('books/list-item', ['book' => $book]) @include('books/list-item', ['book' => $book])
<hr> <hr>
@endforeach @endforeach
@if(count($books) === 10)
<a href="/books">View all books &raquo;</a>
@endif
@else @else
<p class="text-muted">No books have been created.</p> <p class="text-muted">No books have been created.</p>
<a href="/books/create" class="text-pos"><i class="zmdi zmdi-edit"></i>Create one now</a> <a href="/books/create" class="text-pos"><i class="zmdi zmdi-edit"></i>Create one now</a>