[4.0][Feature][WIP] Added catch-all route to all CrudControllers #1932
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solution for #1877
This allows developers to create Operations and Actions for those Operations without having to add an extra route. One less step. This also means it's:
How it works:
entity/do/...
;do
would be the name of the public method that needs to be called on EntityCrudController;So when you add a
public function moderate()
method in your ProductCrudController, you don't need to add a route for it, you can use the catch-all routeproduct/do/moderate
.Of course, it requires developers to be careful about the methods in their Controllers. Only public-facing methods should be
public
. Anything else should beprivate
.PROBLEM 1
One downside to this is that the function parameters don't work as they usually do in Laravel's controller methods - so it's not as intuitive as I wanted it. Since it's gotten to
moderate()
through a catch-all route, NOT something like/{id}/moderate
, you can't dopublic function moderate($id) {}
. You'd have to determine the ID from the URL string. Here's an example with how you can do stuff:And here's the output for

/product/do/moderate/1/2?firstGetVariable=yes&secondGetVariable=no
:You can also call the EXISTING operations over with the
/do/
url:/do/index
works/do/create
works/do/create
works/do/{id}/edit
does NOT work (because of id)/do/{id}/edit
does NOT work (because of id)You get the idea; everything that has an
{id}
in the route will not work when called through the catch-all/do/
- it will only work though its own route.PROBLEM 2
You won't have named routes for these operations. If they're called through a catch-all route, you have to use route actions in URLs, instead of route names.
I would very much like to develop this further. Or merge it as-is. If anybody has any idea how to eliminate one of these problems, please let me know.
Even now, I think the PROs outweigh the CONs. I think for most users they wouldn't matter that much:
product/do/moderate/1
instead ofproduct/do/1/moderate
;backpack_url($crud->entity.'/moderate')
instead ofroute('...')
;Thoughts? Feedback?