📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Laravel Framework Routing

Routing

6 min read Quiz at the end
Define routes with HTTP verbs, parameters, named routes, resource routing, and middleware groups.

Routing in Laravel

// routes/web.php
Route::get("/", fn() => view("welcome"));
Route::get("/about", [PageController::class, "about"]);

// Route parameters
Route::get("/users/{id}", [UserController::class, "show"]);
Route::get("/posts/{post:slug}", [PostController::class, "show"]); // route model binding

// HTTP methods
Route::post("/users", [UserController::class, "store"]);
Route::put("/users/{id}", [UserController::class, "update"]);
Route::delete("/users/{id}", [UserController::class, "destroy"]);
Route::patch("/users/{id}/activate", [UserController::class, "activate"]);

// Resource routes (all CRUD at once)
Route::resource("posts", PostController::class);
Route::apiResource("products", ProductController::class); // API (no create/edit)

// Route groups
Route::prefix("admin")->middleware(["auth", "admin"])->group(function () {
    Route::resource("users", AdminUserController::class);
});

// Named routes
Route::get("/dashboard", fn() => view("dashboard"))->name("dashboard");
echo route("dashboard"); // generates URL
Topic Quiz · 5 questions

Test your understanding before moving on

1. Which method registers a route for all HTTP verbs?
💡 Route::any("/path", handler) matches any HTTP method.
2. What does Route::resource() generate?
💡 Route::resource() creates all 7 RESTful CRUD routes automatically.
3. How do you name a route?
💡 ->name("route.name") assigns a name used with the route() helper.
4. What is route model binding?
💡 Laravel auto-fetches the Eloquent model matching the route parameter.
5. Which helper generates a URL for a named route?
💡 route("posts.show", $post) generates the URL for that named route.