I’m trying to build a resource API with Laravel.
It appears that the approach taken by most is to:
- Create a route for each resource
- Create a controller for each resource
- CRUD logic for each resource either in the controller or deferred to a service for each resource
This seems fine if you’ve only got a couple of resources otherwise you are repeating most of code.
Is there a reason why you wouldn’t create a single catchall route, with a single controller, with a CRUD service that could perform logic whatever the resource?
I appreciate this could be considered an opinionated question, so I am looking for the reasons why either approach would or wouldn’t be taken, or, methods to DRY up the first approach.
Many thanks to any responders.