Is there any way to stop laravel always returning an array, regardless if there is only a single element? I've checked the docs and come up short. It's fine if thats just the way it is of course, just seems a little silly, as you wouldn't post an array to an endpoint, if there was only one element!
Return payload for sanity sake:
[
{
"id": 1,
"created_at": "2015-05-22 15:41:24",
"updated_at": "2015-05-22 15:41:24",
"deleted_at": null,
"closed_loop_interaction_type_id": 1,
"interaction_note": "Test Interaction note",
"closed_loop_processes_id": 1,
"interaction_type": {
"id": 1,
"created_at": "2015-05-22 15:41:24",
"updated_at": "2015-05-22 15:41:24",
"deleted_at": null,
"type": 0,
"method": "Phone Call (mobile)"
}
}
]
That's one object, but sent back as an array of 1. Is there a way to stop this? Is it the way I'm populating models?
$query = ClosedLoopInteraction::with('interactionType');
// Construct a list of headers
$headers = \HeaderHelper::generatePaginationHeader($page, $query, 'closedloop', $limit);
\QueryHelper::handleQueryFiltering(
$query, ['limit'=> $limit, 'page' => $page]);
$response = response()->json($query->get(), \ApiResponse::$STATUS_OK);
// Add the constructed headers to the response
\HeaderHelper::addHeadersToResponse($response, $headers);
return $response;