Skip to content

NOW MANAGED ON CODEBERG

Added limit to books shown on homepage and make alphabetical

Dan Brown76eb8fc5d7ae
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 3f5d338de..d0eb16399 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -36,7 +36,7 @@ class HomeController extends Controller
*/
public function index()
{
- $books = $this->bookRepo->getAll();
+ $books = $this->bookRepo->getAll(10);
$activity = $this->activityService->latest();
return view('home', ['books' => $books, 'activity' => $activity]);
}
diff --git a/app/Repos/BookRepo.php b/app/Repos/BookRepo.php
index c94817eb3..87309501e 100644
--- a/app/Repos/BookRepo.php
+++ b/app/Repos/BookRepo.php
@@ -25,9 +25,9 @@ class BookRepo
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();
}
/**
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php
index 32bfbd028..2a97c4839 100644
--- a/resources/views/home.blade.php
+++ b/resources/views/home.blade.php
@@ -11,6 +11,9 @@
@include('books/list-item', ['book' => $book])
<hr>
@endforeach
+ @if(count($books) === 10)
+ <a href="/books">View all books &raquo;</a>
+ @endif
@else
<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>