dingo / dingo/api

Middleware not woking

Open
#1,393 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Hi, I'm trying to filter a JSON request using a middleware but It doesn't appear to be working.

A request like this will work just fine
```
{"username":"username","email":"test@email.com","password":"password","confirm_password":"password"}
```

But one like this will throw validation errors saying that the fields are required
```
{"data":{"attributes":{"username":"username","email":"test@email.com","password":"password","confirm_password":"password"},"type":"users"}}
```

I've got a middleware that is meant to filter out the `data` and `attributes` part of the object and leave the content, It looks like this

```
public function handle($request, Closure $next)
{
$input = $request->all();

if (isset($input['data']['attributes'])) {
$input = $input['data']['attributes'];

$request->replace($input);
\Log::info($request->all());
}

return $next($request);
}
```

That log you see in the above method logs out the response I'm looking for
```
[2017-05-22 06:32:03] local.INFO: array (
'username' => 'username',
'email' => 'test@email.com',
'password' => 'password',
'confirm_password' => 'password',
)
```

But I still get the error
```
{"error":{"message":"422 Unprocessable Entity","errors":{"username":["The username field is required."],"email":["The email field is required."],"password":["The password field is required."],"confirm_password":["The confirm password field is required."]},"status_code":422}}
```

Does anybody know what would be causing this issue? Any help is greatly appreciated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.