Route Connector — Laravel

Connect Laravel routes: 12 levels of Route::get, parameters, names and groups. A Laravel routing game for mastering request handling.

What you learn in this game

A route maps (method + URL pattern) to one handler. A static route like /tentang matches only that exact path. Define: route GET /tentang about.

The {id} placeholder captures one URL segment. One route /users/{id} serves /users/5, /users/9, etc. The captured value becomes a handler parameter.

Laravel matches routes in order, first match wins. /users/{id} also matches /users/baru (id="baru"). So specific static routes must be registered before parameterized ones.

The constraint where id [0-9]+ restricts a parameter with a regex. /users/budi no longer matches (letters) → 404. Without a constraint, {id} captures anything.

Routes are distinguished by method + pattern, not pattern alone. GET /users/{id} and DELETE /users/{id} are two different routes with different handlers: the heart of REST.

An optional placeholder {slug?} lets a segment be present or not. /posts and /posts/halo both match one route. Useful for a list + detail that share a handler.

What the levels ask

  1. Connect the request GET /tentang to the handler about.
  2. Point GET /users/5 and GET /users/9 to the show handler with one parameterized route.
  3. GET /users/baru → create, GET /users/5 → show. Arrange the route order so both are correct.
  4. GET /posts/{slug} → posts.show, GET /tags/{tag} → tags.show.
  5. GET /users/3/posts/9 → user.post. Capture two parameters at once.
  6. GET /users/5 → show, but GET /users/budi must 404. Restrict {id} to digits only.
  7. GET /users/5 → byId, GET /users/budi → byName. Distinguish via constraints.
  8. GET /users/5 → show, DELETE /users/5 → destroy. Same pattern, different method.
  9. GET /posts → posts.index AND GET /posts/halo → posts.index. One route for both.
  10. GET /users/5/edit → edit, GET /users/5 → show.
  11. GET /home → home, GET /admin must 404 (don't make a route for it).
  12. GET /produk/12 → show, GET /produk/abc must 404. Only numeric ids are valid.

And more, 18 levels in all.