I've read several threads where people had problems testing their controllers by posting json to them - I tried the same and cannot get it to work as well...
What I'm trying to do is:
$data = json_encode([...some-data...]);
$response = $this->call(
'POST', 'api/v1/handle', [], [], [], [], $data);
When I debug in the corresponding controller...
public function store(Request $request)
{
$data = $request->all();
}
... I can see the data (json string) is set in the Request::content property but its not available in $data when trying to retrieve it with $request->all(). When I POST from the Javascript in the frontend, which is sending plain json in the request payload everything is available from $request->all() . Whats the missing point on using ApplicationTrait::call() ?? I can't see it.
Okay.. I found it.
// In the controller
$data = $request->json();
It works now for both, making requests from the browser or the test class...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community