You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Laravel 5.5 and wonder if I can not only group routes by name prefixes and route prefixes but also controllers since they all use the same controller. The documentation didn't provide anything the like. Here's what I currently have:
Short handing the code bit by using a variable ($controller = 'MyRouteController'; in the group(), then Route::get('/ajax', "{$controller}@ajax")) doesn't make the code much shorter though and would require an additional line of code.
In Laravel 4 there were implicit controllers available by using Route::controller() but that's not what I'm looking for since this won't be implicit.
Another approach would be using Resource Controllers. But I discarded that idea, because Resources are mainly used for RESTful APIs and therefore unnecessary routes are created (unnecessary but not problematic per se). But if I intend to misuse Resources for that purpose I have to supplement the controller upfront in order to achieve that behavior which seems a little messy and undesirable to me. Nonetheless, in general that does work …
Prospects
Anyhow, both approaches are not very satisfying, which brings me back to my original code snippet. If there's no approach which can do what I outlined, is there a fair chance, this could be implemented?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Current situation
I'm using Laravel 5.5 and wonder if I can not only group routes by name prefixes and route prefixes but also controllers since they all use the same controller. The documentation didn't provide anything the like. Here's what I currently have:
Goal
And it should look something like that:
Is there a way to achieve this kind of behavior?
Approaches
Short handing the code bit by using a variable (
$controller = 'MyRouteController';
in thegroup()
, thenRoute::get('/ajax', "{$controller}@ajax")
) doesn't make the code much shorter though and would require an additional line of code.In Laravel 4 there were implicit controllers available by using
Route::controller()
but that's not what I'm looking for since this won't be implicit.Another approach would be using Resource Controllers. But I discarded that idea, because Resources are mainly used for RESTful APIs and therefore unnecessary routes are created (unnecessary but not problematic per se). But if I intend to misuse Resources for that purpose I have to supplement the controller upfront in order to achieve that behavior which seems a little messy and undesirable to me. Nonetheless, in general that does work …
Prospects
Anyhow, both approaches are not very satisfying, which brings me back to my original code snippet. If there's no approach which can do what I outlined, is there a fair chance, this could be implemented?
Beta Was this translation helpful? Give feedback.
All reactions