Skip to content

Can I get request from the middleware? #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FuturFuturFutur opened this issue Mar 18, 2021 · 2 comments
Closed

Can I get request from the middleware? #51

FuturFuturFutur opened this issue Mar 18, 2021 · 2 comments

Comments

@FuturFuturFutur
Copy link

I am working on package which I believe will build auto generated api documentation. It works based on tests coverage using middleware like this:

public function handle(Request $request, Closure $next)
    {
        $response = $next($request);

        if(Config::get('app.debug'))
            $this->docDocDocService->parse($request, $response);

        return $response;
    }

I can get request and response from each test, so I have status codes, parameters, bodies, headers, etc. Now I want to get validation rules from form requests. It works fine with form requests injected to the action as a parameter, as I can see json api server requests are not injected to action, but are initializing inside the actions, like this:

$request = ResourceQuery::queryOne(
            $resourceType = $route->resourceType()
        );

I can't see any possibility to get it inside the scope of the request, do you?

@lindyhopchris
Copy link
Contributor

The problem with Laravel form requests is they are validated as soon as they are resolved by the service container. So getting them at any point other than the point you want validation to occur isn't possible. That's a design problem with Laravel's form requests, rather than this package.

So for the moment this isn't possible.

I'm going to have to decouple validation from form requests to deliver #39. But I'm not sure when I'll get to that as this package is already taking an incredible amount of my time, and I'm starting to get behind on real work as a result.

@FuturFuturFutur
Copy link
Author

Got it, thanks for a fast response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants