ControllerDispatcher not working when routes are cached
emsifa opened this issue · comments
Muhammad Syifa commented
Description
Emsifa\Evo\ControllerDispatcher
doesn't dispatch request attributes when routes are cached.
- Evo Version:
v0.3.2
- Laravel Version:
v8.54
Step to Reproduce
- Create a controller:
php artisan make:controller LoginController
- Create DTO:
php artisan evo:make-dto LoginDto username:string password:string
- In
LoginController
, add method below:#[Post('login')] public function login(#[Body] LoginDto $dto) { return response()->json(['data' => $dto]); }
- Register route in
routes/api.php
:EvoFacade::routes(LoginController:::class);
- Run built-in server:
php artisan serve
- Execute CURL without cache:
It response data with request payload.
curl -s -X POST http://localhost:8000/api/login \ -H 'Content-type: application/json' \ -d '{"username": "johndoe", "password": "secret"}'
- Cache routes:
php artisan route:cache
- Execute CURL again (with cache):
Now the data is empty JSON object.
curl -s -X POST http://localhost:8000/api/login \ -H 'Content-type: application/json' \ -d '{"username": "johndoe", "password": "secret"}'
Expectation
When routes are cached, the data should be filled with request data.
Assumption
It doesn't work because Laravel map cached routes into Illuminate\Routing\Route
instance which use Illuminate\Container\Container\ControllerDispatcher
instead of Emsifa\Evo\ControllerDispatcher
.