Connect Laravel routes: 12 levels of Route::get, parameters, names and groups. A Laravel routing game for mastering request handling.
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.
about.show handler with one parameterized route.create, GET /users/5 → show. Arrange the route order so both are correct.posts.show, GET /tags/{tag} → tags.show.user.post. Capture two parameters at once.show, but GET /users/budi must 404. Restrict {id} to digits only.byId, GET /users/budi → byName. Distinguish via constraints.show, DELETE /users/5 → destroy. Same pattern, different method.posts.index AND GET /posts/halo → posts.index. One route for both.edit, GET /users/5 → show.home, GET /admin must 404 (don't make a route for it).show, GET /produk/abc must 404. Only numeric ids are valid.And more, 18 levels in all.