Resource Controllers and Route Model Binding
Most controllers in a typical Laravel application end up handling the same predictable set of actions: listing records, showing one, creating, updating, and deleting. Laravel packages this pattern into resource controllers, paired with route model binding to remove even more repetitive code.
Resource Controllers
Instead of manually defining a route for every CRUD action, a single line can register all of them at once, mapped to conventionally named controller methods. This keeps route files short while still following RESTful conventions that other developers immediately recognize.
| HTTP Verb | Action | Route |
|---|---|---|
| GET | index (list all) | /posts |
| GET | create (show form) | /posts/create |
| POST | store (save new) | /posts |
| GET | show (view one) | /posts/{post} |
| GET | edit (show edit form) | /posts/{post}/edit |
| PUT/PATCH | update (save changes) | /posts/{post} |
| DELETE | destroy (remove) | /posts/{post} |
Route Model Binding
Normally, a controller method receiving an ID has to manually look up the matching database record before doing anything useful. Route model binding removes that step entirely: Laravel inspects the type-hinted model in the method signature and automatically injects the correct record, or returns a 404 if it doesn't exist.
- Eliminates repetitive "find or fail" lookup code in every method
- Keeps controller methods focused on actual business logic
- Supports binding by custom fields, such as a slug instead of an ID
With controllers returning data reliably, the next step is learning how to actually display that data to users — starting with Blade, Laravel's built-in templating engine.
Ready to master Laravel Training Course?
Join Uncodemy's hands-on Laravel program and build real, production-ready applications.
