updated returnAsResource parameters

This commit is contained in:
2023-03-29 15:46:06 +10:00
parent 06c9d48126
commit c96b3d8349
7 changed files with 23 additions and 31 deletions

View File

@@ -122,19 +122,18 @@ class ApiController extends Controller
* Return resource data
*
* @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 string|null $resourceName The resource name to group the result.
* @param integer $respondCode Resource code.
* @param array $options Respond options.
* @return \Illuminate\Http\JsonResponse
*/
protected function respondAsResource(
mixed $data,
bool $isCollection = false,
mixed $appendData = null,
string $resourceName = null,
int $respondCode = HttpResponseCodes::HTTP_OK
array $options = [],
) {
$isCollection = $options['isCollection'] ?? false;
$appendData = $options['appendData'] ?? null;
$resourceName = $options['resourceName'] ?? null;
$respondCode = $options['respondCode'] ?? HttpResponseCodes::HTTP_OK;
if ($data === null || ($data instanceof Collection && $data->count() === 0)) {
return $this->respondNotFound();
}