I am trying to convert the JSON Request $request
to an array.
I have output something like this:
^ Symfony\Component\HttpFoundation\Request {#45+attributes: Symfony\Component\HttpFoundation\ParameterBag {#74 #parameters: array:3 ["_route" => "app_movie_create""_controller" => "App\Controller\MovieController::create""_route_params" => [] ] }+request: Symfony\Component\HttpFoundation\ParameterBag {#96 #parameters: [] }+query: Symfony\Component\HttpFoundation\ParameterBag {#69 #parameters: array:1 ["title" => "Homecoming" ] }
I have seen some tutorials giving following solutions.
$data = json_decode($request->getContent(), true); if (json_last_error() !== JSON_ERROR_NONE) { throw new BadRequestHttpException('invalid json body: ' . json_last_error_msg()); }
But I am getting null in my case.
I can do like this. $request->get('title');