-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix artisan routes Output #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix artisan routes Output #22
Conversation
…es to the artisan routes command.
…nt of routes, when both API routes and normal routes are added to the Router
What happens if there is a duplicate route in both the API routes and the default routes? Say, for example: $this->router->api(['version' => 'v1', 'prefix' => 'api'], function() { $this->router->get('foo', function() { return 'bar'; }); });
$this->router->get('foo', function() { return 'baz'; }); Do both routes still show up in |
No, if you were to do the above, you would only get a single route. Is such a thing allowed? If you made the route Also it looks like if you do the following:
You would only get a single route |
The API is able to have the same URIs as regular routes. That's why they are registered in their own route collections. My above example has a I've been thinking about this and I was thinking of just adding an |
I didn't notice the |
Also a quick test show that your example above would infact still return both routes. I can adjust the unit test to match your example, if that's the result you're intending. |
And it shows up in |
Correct, you would get two different listings after running |
Okay cool! I'll have a play with this shortly and will then merge. 😄 Cheers. |
Sounds good! As for that |
Hm, there are still going to be problems with this so I think we should just have an The biggest problem I've seen after checking it out is that if I have the following it will only register the last route. Route::api(['version' => 'v1', 'prefix' => 'api'], function()
{
Route::get('users', 'Api\V1\UsersController@index');
});
Route::api(['version' => 'v2', 'prefix' => 'api'], function()
{
Route::get('users', 'Api\V2\UsersController@index');
}); If you run |
Yea I realized this last night as I was getting ready to passout. I was trying to maintain the functions original function of returning a RouteCollection, but in cases like the above, it results in duplicates not showing up. I'll mess around with the idea of the |
@hskrasek Have you had a chance to look at a new command yet? Otherwise I'm going to look at throwing something together later. Cheers. |
Very briefly, but I'm starting my last week of finals this week. Then I'll be done with undergrad and be able to do more of this stuff! I'll try to mess around with it tomorrow, if not for sure Wednesday afternoon. ---Hunter Skrasekhunterskrasek@me.com On May 4, 2014 at 10:22:25 PM CDT, Jason Lewis notifications@github.com wrote:@hskrasek Have you had a chance to look at a new command yet? Otherwise I'm going to look at throwing something together later. Cheers. —Reply to this email directly or view it on GitHub. |
Instead of using the existing Laravel router we will use a new instance. This should prevent the APIs internal dispatcher from overriding the current route on the actual Laravel router instance. There does not seem to be any need for the router instance that is injected into the adapter to be the actual Laravel router, as the adapter just needs an instance to dispatch the API-only routes.
I noticed after changing my api routes to use Route::api(), that when I ran artisan routes those routes were gone. So did some poking around, and I believe I came up with a solution that resolves the issue.
Tested it in one of my projects, and artisan routes is returning the correct input.
Hopefully the test I added adequately covers the change, if not let me know and I can add another test or two.. after I think of them.