trait JsonResponse

A trait that support operations related to APIs and their associated JSON responses.

Methods

bool
apiCsrfCheck()

Checks if CSRF token has been tampered with.

array|string
get(string|null $input = null)

Supports operations related to handling POST and GET requests.

void
jsonError(string $message, int $status = 400, array $errors = [])

Makes JSON Response for error payloads.

void
jsonResponse(mixed $data, int $status = 200, array $extraHeaders = [])

Sends a JSON response with headers and status code.

void
preflight()

Respond to CORS preflight.

Details

at line 20
bool apiCsrfCheck()

Checks if CSRF token has been tampered with.

Return Value

bool

True if token is valid, otherwise we return false.

at line 35
array|string get(string|null $input = null)

Supports operations related to handling POST and GET requests.

Similar in behavior to the get function from the Input class but for JSON related operations.

Parameters

string|null $input

Field name from POST/GET request, or null to get all

Return Value

array|string

Sanitized input as array or string

at line 69
void jsonError(string $message, int $status = 400, array $errors = [])

Makes JSON Response for error payloads.

Parameters

string $message

The error message.

int $status

The status code.

array $errors

The array of errors.

Return Value

void

at line 84
void jsonResponse(mixed $data, int $status = 200, array $extraHeaders = [])

Sends a JSON response with headers and status code.

Parameters

mixed $data

The JSON response.

int $status

The status code.

array $extraHeaders

Any extra headers.

Return Value

void

at line 117
void preflight()

Respond to CORS preflight.

Return Value

void