# Extending the Request class

**URL:** <https://forum.shopware.com/t/extending-the-request-class/103867>\
**Category:** Shopware 6 (English)\
**Tags:** administration, programming\
**Created:** [27. April 2024 um 11:30 UTC](https://forum.shopware.com/t/extending-the-request-class/103867 "2024-04-27T11:30:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donny](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Donny](https://forum.shopware.com/u/Donny)\
**Post date:** [27. April 2024 um 11:30 UTC](https://forum.shopware.com/t/extending-the-request-class/103867/1 "2024-04-27T11:30:04Z")

</div>

Hi,

Im trying to extend the Symfony Request class to clean up some code. As a example:

```auto
<?php

    namespace Plugin\Name\Http\Requests;

    use Symfony\Component\HttpFoundation\Request;

    class ValidateExampleRequest extends Request
    {
        public function getEmail()
        {
            return $this->get('email');
        }
    }

```

After this I created a controller and injected my Request Class into the controller method.

```auto
<?php declare(strict_types=1);

    namespace Plugin\Name\Http\Controllers;
    
    use Shopware\Storefront\Controller\StorefrontController;
    use Symfony\Component\HttpFoundation\JsonResponse;
    use Symfony\Component\Routing\Attribute\Route;

    #[Route(defaults: ['_routeScope' => ['storefront']])]
    class ExampleController extends StorefrontController
    {
        #[Route(path: '/example', name: 'storefront.plugin.name.example', methods: ['get'])]
        public function example(ValidateExampleRequest $validateRequest)
        {
            return new JsonResponse([
                'email' => $validateRequest->getEmail()
            ]);
        }
    }

```

After calling the URL I’m getting the following error:

```auto
Plugin\Name\Http\Controllers\ExampleController::example(): Argument #2 ($validateRequest) must be of type Plugin\Name\Http\Requests\ValidateExampleRequest, Symfony\Component\HttpFoundation\Request given, called in /var/www/html/vendor/symfony/http-kernel/HttpKernel.php on line 178

```

How can I inject my custom Request class to this controller method?

---

<div class="post-metadata">

**Author:** ![aggrosoft](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/aggrosoft/32/23875_2.png) [@aggrosoft](https://forum.shopware.com/u/aggrosoft)\
**Post date:** [30. April 2024 um 14:24 UTC](https://forum.shopware.com/t/extending-the-request-class/103867/2 "2024-04-30T14:24:20Z")

</div>

did you register your custom request class as a service? Show your services.xml as well
