Skip to content

Route different HTTP verbs to different methods, with the same route name, with annotations #45218

@Bilge

Description

@Bilge

Description

Symfony supports routing different HTTP verbs to the same method with the same route name, but not different methods with the same route name.

    /**
     * @Route("/foo", name="foo", methods={"GET", "POST"})
     */
     public function __invoke() {}

However, if we want to split this out into two methods, this is not possible.

    /**
     * @Route("/foo", name="foo", methods={"GET"})
     */
     public function get() {}

    /**
     * @Route("/foo", name="foo", methods={"POST"})
     */
     public function post() {}

In this case, the latter definition overwrites the former, since they have the same name. Yet the same name is permitted for different verbs, provided they are backed by the same controller method. In my view this is problematic because Symfony routing limitations should not hamstring the implementation.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions