added tests, bug fixes and cleanup

This commit is contained in:
2023-03-13 16:03:32 +10:00
parent 44b123307a
commit 2cea90c2c8
21 changed files with 443 additions and 40 deletions

View File

@@ -121,13 +121,15 @@ class ApiController extends Controller
/**
* Return resource data
*
* @param array|Model|Collection $data Resource data.
* @param array|null $appendData Data to append to response.
* @param integer $respondCode Resource code.
* @param array|Model|Collection $data Resource data.
* @param boolean $isCollection If the data is a group of items.
* @param array|null $appendData Data to append to response.
* @param integer $respondCode Resource code.
* @return \Illuminate\Http\JsonResponse
*/
protected function respondAsResource(
mixed $data,
bool $isCollection = false,
mixed $appendData = null,
int $respondCode = HttpResponseCodes::HTTP_OK
) {
@@ -144,8 +146,6 @@ class ApiController extends Controller
$resourceName = strtolower($resourceName);
}
$is_multiple = true;
$dataArray = [];
if ($data instanceof Collection) {
$dataArray = $data->toArray();
@@ -157,7 +157,7 @@ class ApiController extends Controller
}
$resource = [];
if ($is_multiple === true) {
if ($isCollection === true) {
$resource = [Str::plural($resourceName) => $dataArray];
} else {
$resource = [Str::singular($resourceName) => $dataArray];