If you're in the controller you can type hint the Requestobject into your method to get access to the request parameters and then you can validate the data as if it were any other request
Aug 21, 2017
1
Level 1
JSON_encode some request parameters
Hello,
I want to create an update controller, which will perform some validation action and then update the database.
Sometimes the payload is just:
{ "log": true }
Which works fine!
But sometimes it looks like this:
{ "title": "test", "data": { "account": { "username": "test", "password": "test" } } }
Which doesn't work by default. Error I get:
Array to string conversion
This only works when I do:
json_encode($request->get('data'))
Is there a way you can do this:
If data is present then json_encode this part.. (the rest remains as is)
Please let me know, other wise I need to create 2 endpoints. (which I do not like)
R
Please or to participate in this conversation.