What you can do after this lesson
You will have a finished, tested Pagelane Books app and a clear picture of how its parts fit. You will also add one last feature by yourself-style, following the same steps you used throughout: route, controller, view, test.
The last feature: category pages
Visitors should be able to browse by category. Everything needed already exists: the Category model, the books() relationship and the published() scope.
Route. Use route model binding on the slug so URLs read well:
Route::get('/categories/{category:slug}', [CategoryController::class, 'show'])->name('categories.show');{category:slug} tells Laravel to find the category by its slug column, and to answer 404 when there is none.
Controller.
class CategoryController extends Controller
{
public function show(Category $category): View
{
$books = $category->books()
->published()
->orderBy('title')
->paginate(config('shop.per_page'));
return view('categories.show', ['category' => $category, 'books' => $books]);
}
}View, reusing the layout and the card component from the Blade lessons:
<x-layout :title="$category->name">
<h1>{{ $category->name }}</h1>
@forelse ($books as $book)
<x-book-card :book="$book" />
@empty
<p>No books in this category yet.</p>
@endforelse
{{ $books->links() }}
</x-layout>Home page. The home controller now passes the categories, and the view lists them:
return view('home', ['categories' => Category::orderBy('name')->get()]);<ul>
@foreach ($categories as $category)
<li><a href="{{ route('categories.show', $category) }}">{{ $category->name }}</a></li>
@endforeach
</ul>Passing the model to route() works with the slug binding, because Laravel uses the model's route key; the generated links were .../categories/crime and .../categories/fiction. With the seeded database the Crime page showed its six published books, and /categories/nope answered 404.
The suite catches a side effect
Run the tests after the change:
php artisan test Tests: 2 failed, 34 passed (96 assertions)The failures were ExampleTest and PagesTest, both requesting /, with the message no such table: categories. The home page now reads the database, but these two test classes were written back when it did not, and they lacked RefreshDatabase. The fix is to add the trait to both:
use Illuminate\Foundation\Testing\RefreshDatabase;
class PagesTest extends TestCase
{
use RefreshDatabase;
// ...
}Then add two tests for the new feature in CatalogueTest:
public function test_a_category_page_lists_only_its_own_books(): void
{
$fiction = Category::factory()->create(['name' => 'Fiction', 'slug' => 'fiction']);
Book::factory()->for($fiction)->create(['title' => 'A Fiction Book']);
Book::factory()->create(['title' => 'Elsewhere Book']);
$this->get('/categories/fiction')
->assertOk()
->assertSee('A Fiction Book')
->assertDontSee('Elsewhere Book');
}
public function test_an_unknown_category_is_a_404(): void
{
$this->get('/categories/nope')->assertNotFound();
} Tests: 36 passed (97 assertions)This is the everyday rhythm of development: change something, run the suite, read the failure, fix the cause, add tests for the new behaviour.
A map of the finished app
As of 2026-11, on Laravel 13.42.0 and PHP 8.4, Pagelane Books has:
| Area | What it contains | Lessons |
|---|---|---|
| Public pages | Home, catalogue with search and pagination, book detail, category pages, contact form | Routing, Blade, forms, Eloquent |
| Accounts | Registration, login, logout, remember me, throttled login | Authentication, security |
| Access control | auth, guest and admin middleware, gate, policies |
Middleware, authorization |
| Admin area | Book create, edit, delete with cover upload | File uploads |
| Reviews | One review per user per book, delete by author or admin | Relationships, policies |
| JSON API | Books list and detail, token endpoint, review creation with abilities | API lessons |
| Background work | Events, listeners, queued jobs, mail to admins, cached ratings | Queues, events, mail, caching |
| Quality | 36 tests, friendly error pages, logging, rate limits | Testing, errors, security |
php artisan route:list --except-vendor showed 28 routes, and the project holds 82 hand-written or generated files across app, database, resources/views, routes and tests (as counted before the category feature was added, so slightly more now). Every one of them was created by a command or code you saw in a lesson.
Final review
Go through this list with the project open:
- Structure. Controllers are thin, rules live in form requests and policies, and views contain no queries.
- Data. Every table has a migration with a working
down(); fillable lists exclude sensitive columns; N+1 queries are avoided withwith(). - Security. Every changing route has
authplus authorization; output is escaped; secrets are only in.env; login and contact are rate limited;composer auditwas clean when run on 2026-11. - Testing.
php artisan testis green, and denied cases are tested as well as allowed ones. - Operations. Errors are logged without secrets, workers are restarted on deploy, and the deployment checklist is written down.
- Docs. Someone new can run
composer install, copy.env.example, generate a key, runphp artisan migrate --seedandphp artisan test.
Things this course deliberately did not build: a shopping cart and payments, email verification, password reset, a front-end build with Vite and a CSS framework, search at scale, a scheduler, and a production deployment. Each is a good next project; payments and personal data in particular need careful design and legal review.
Where to go next
- Extend the app: tag pages, a wishlist, password reset, email verification, an order model.
- Try a starter kit in a throwaway project to compare it with the hand-built login.
- Learn the front end tooling: Vite and a CSS approach of your choice.
- Read the official documentation for your version at laravel.com, starting with the request lifecycle and the service container, which this course only touched.
- Strengthen PHP: the PHP course and the MySQL course deepen the foundations, and the Composer course explains the packages that Laravel is built from.
Common mistakes
- Not running the whole suite after a "small" change, as the failing home page tests showed.
- Adding features without tests.
- Skipping the final review, so debug mode or default demo accounts reach production.
- Copying code you do not understand. Read it and run it.
- Treating the course app as production-ready. It is a teaching project.
Exercise
Add tag pages: /tags/{tag:slug} listing published books with that tag, linked from the book detail page, with a test. Which relationship method and scope do you use?
Show one possible answer
Route::get('/tags/{tag:slug}', [TagController::class, 'show'])->name('tags.show');public function show(Tag $tag): View
{
$books = $tag->books()->published()->orderBy('title')->paginate(config('shop.per_page'));
return view('tags.show', ['tag' => $tag, 'books' => $books]);
}Use Tag::books() (a belongsToMany relationship) with the published() scope. In books/show.blade.php link each tag with route('tags.show', $tag). The test creates a tag, attaches it to one book with $book->tags()->attach($tag), and asserts the tagged book is visible and an untagged one is not. Congratulations: you have built and tested a complete Laravel application.
Key points
- The capstone adds category pages with route model binding on the slug, a home page that lists categories, and tests for both.
- Changing the home page to read the database broke two tests that had no database, a realistic reminder to run the suite after every change.
- The finished app has 28 routes, 36 passing tests, a Blade front end, an admin area, a JSON API with Sanctum tokens, queued mail and caching.
- A final review walks through structure, security, quality and deployment against the earlier lessons.
- Next steps are practice features, a real front-end build with Vite, and reading the official documentation for your Laravel version.
Check yourself
Final exam and certificate
Finish all 40 lessons to unlock a 15-question exam on Laravel. Pass it and you get a certificate with a public link you can share.
Sign in to take the exam