Closed rafee12 closed 2 years ago
Hey, thanks for the report, but the Laravel documentation says quite the opposite:
You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.
This works correctly in Laravel, which waits for the application to be booted before registering routes:
I don't know if this is an intentional limitation of Lumen or could be considered a bug, but I don't think it's something we could solve on our side.
I would suggest trying Lumen support channels, reworking your fallback implementation (maybe you could catch the not found exception?) or just using Laravel.
hahaha.., my bad, because I posted the issue while busy doing something else, so I took a quick look at registering the route in the documentation and didn't read carefully, thanks for reminding me about register method.
after tracing the issue, Lumen and Laravel have different places when the route is registered. Laravel registering the main route in the service provider, so the clockwork won't be a problem with Laravel
bootstrap -> kernel -> service provider (clockwork) -> service provider (route)
but Lumen registering the main route in the bootstrap (maybe because Lumen doesn't have kernel)
bootstrap (with route) -> service provider (clockwork)
the solution is to create a route service provider and move the part of registering the main route in bootstrap to the service provider, so it will work like Laravel. Maybe you can add a note for Lumen in the clockwork documentation, so the clockwork service providers will no have any problems with the Lumen routes.
thank you
As we know Laravel has route fallback function, but lumen doesn't have it, so we use solution like
$router->get('/{route:.*}/', function () { /* fallback */ });
for any incoming route.But if we use clockwork in Lumen with route fallback like the route before, it will show
Static route "/clockwork" is shadowed by previously defined variable route "/(.*)" for method "GET"
the problem is the clockwork registering routes, event listeners, and middlewares in boot method, not in register method as Laravel/Lumen recommends in the documentation https://laravel.com/docs/8.x/providers#writing-service-providers https://lumen.laravel.com/docs/8.x/providers#writing-service-providers
so in this line https://github.com/itsgoingd/clockwork/blob/043e57df220e9c4e3a01b7ed8a99ad48c4555b6c/Clockwork/Support/Laravel/ClockworkServiceProvider.php#L37 will registering route after the Lumen's main route.
I don't know if registering the routes in the boot method was intentionally to override the main routes, so the clockwork keeps running. But as i know, registering a route as a Laravel/Lumen Service Provider should not interfere with the main routes.