Skip to content
Guest
Laravel · Course Syllabus Show lessons
Core Laravel · 8 min read · Intermediate

Routing, Route Model Binding & Controllers

Define clean RESTful routes, group middleware, and inject Eloquent models automatically via Route Model Binding.

What you'll learn

  • Map HTTP verbs to controller actions cleanly in `routes/web.php` and `routes/api.php`
  • Use implicit Route Model Binding (`{course:slug}`) to avoid manual `findOrFail()` calls
  • Organize CRUD endpoints with `Route::resource()` and route groups

Overview

Define clean RESTful routes, group middleware, and inject Eloquent models automatically via Route Model Binding.

Code Example

<?php
use App\Http\Controllers\CourseController;
use Illuminate\Support\Facades\Route;

Route::get('/courses', [CourseController::class, 'index'])->name('courses.index');
Route::get('/courses/{course:slug}', [CourseController::class, 'show'])->name('courses.show');

Route::middleware('auth')->group(function () {
    Route::resource('notes', NoteController::class)->except(['show']);
});

Key Takeaways

  • Map HTTP verbs to controller actions cleanly in routes/web.php and routes/api.php
  • Use implicit Route Model Binding ({course:slug}) to avoid manual findOrFail() calls
  • Organize CRUD endpoints with Route::resource() and route groups

Quick Check

Check Your Understanding

Score: 0 / 1

1. What happens when a route uses `{post}` with a typed `Post $post` controller parameter and the ID does not exist?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind