emsifa / evo

Evolve your Laravel code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ControllerDispatcher not working when routes are cached

emsifa opened this issue · comments

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:
    curl -s -X POST http://localhost:8000/api/login \
      -H 'Content-type: application/json' \
      -d '{"username": "johndoe", "password": "secret"}'
    
    It response data with request payload.
  • Cache routes:
    php artisan route:cache
    
  • Execute CURL again (with cache):
    curl -s -X POST http://localhost:8000/api/login \
      -H 'Content-type: application/json' \
      -d '{"username": "johndoe", "password": "secret"}'
    
    Now the data is empty JSON object.

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.