Closed vastarparagopal closed 9 months ago
Hello,
Thanks for your reporting, on a quick look i think the API is not receiving your body, can you confirm request()->all()
contains your mutate array ?
There are tests running on this: https://github.com/Lomkit/laravel-rest-api/blob/master/tests/Feature/Controllers/MutateUpdateOperationsTest.php
Anyway this error should be validated so i'll add a check
I can confirm this is working using basic documentation generated. If you are still facing this issue please reopen the issue providing more details
Hello, @GautierDele
When i called the API api/users/mutate from postman to create a new User they give me below error
{ "message": "The mutate.0.attributes field must be an array.", "errors": { "mutate.0.attributes": [ "The mutate.0.attributes field must be an array." ] } }
This is body param that i pass { "mutate": [ { "operation": "create", "attributes": { "name": "Gautier Deleglise", "email": "gautier@mail.com", "password": "password" } } ] }
This is a misleading information, basically your field is not allowed in the "fields" method. Please add it, ill leave this issue open and fix it soon to make it more clear
@vastarparagopal changed in #45 thanks for your feedback
Laravel Rest Api Version
1.0
Laravel Version
10.10
PHP Version
8.1
Database Driver & Version
No response
Description
When call API for create user its give below error
Steps To Reproduce
Request Body
{ "mutate": [ { "operation": "create", "attributes": ["name": "Gautier Deleglise", "email": "gautier@mail.com", "password": "password"] }, { "operation": "create", "attributes": ["name": "My other user", "email": "him@mail.com", "password": "password"] } ] }
Got error
{ "message": "Undefined array key \"mutate\"", "exception": "ErrorException", "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/lomkit/laravel-rest-api/src/Query/Traits/PerformMutation.php", "line": 34, "trace": [ { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php", "line": 254, "function": "handleError", "class": "Illuminate\Foundation\Bootstrap\HandleExceptions", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/lomkit/laravel-rest-api/src/Query/Traits/PerformMutation.php", "line": 34, "function": "Illuminate\Foundation\Bootstrap\{closure}", "class": "Illuminate\Foundation\Bootstrap\HandleExceptions", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/lomkit/laravel-rest-api/src/Concerns/PerformsRestOperations.php", "line": 73, "function": "mutate", "class": "Lomkit\Rest\Query\Builder", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Controller.php", "line": 54, "function": "mutate", "class": "Lomkit\Rest\Http\Controllers\Controller", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php", "line": 43, "function": "callAction", "class": "Illuminate\Routing\Controller", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 260, "function": "dispatch", "class": "Illuminate\Routing\ControllerDispatcher", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 205, "function": "runController", "class": "Illuminate\Routing\Route", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 799, "function": "run", "class": "Illuminate\Routing\Route", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 141, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php", "line": 50, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Routing\Middleware\SubstituteBindings", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php", "line": 159, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php", "line": 135, "function": "handleRequest", "class": "Illuminate\Routing\Middleware\ThrottleRequests", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php", "line": 87, "function": "handleRequestUsingNamedLimiter", "class": "Illuminate\Routing\Middleware\ThrottleRequests", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Routing\Middleware\ThrottleRequests", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/sanctum/src/Http/Middleware/EnsureFrontendRequestsAreStateful.php", "line": 25, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 141, "function": "Laravel\Sanctum\Http\Middleware\{closure}", "class": "Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 116, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/sanctum/src/Http/Middleware/EnsureFrontendRequestsAreStateful.php", "line": 26, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 116, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 800, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 777, "function": "runRouteWithinStack", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 741, "function": "runRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 730, "function": "dispatchToRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 200, "function": "dispatch", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 141, "function": "Illuminate\Foundation\Http\{closure}", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 21, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php", "line": 31, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TransformsRequest", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 21, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php", "line": 40, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TransformsRequest", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TrimStrings", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php", "line": 27, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php", "line": 89, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php", "line": 62, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Http\Middleware\HandleCors", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php", "line": 39, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 180, "function": "handle", "class": "Illuminate\Http\Middleware\TrustProxies", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 116, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 175, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 144, "function": "sendRequestThroughRouter", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/public/index.php", "line": 52, "function": "handle", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/var/www/html/demo-projects/laravel-rest-api/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php", "line": 16, "function": "require_once" } ] }