JsonResponse
class JsonResponse extends JsonResponse
Traits
Properties
| mixed | $original | The original content of the response. |
from ResponseTrait |
| Throwable|null | $exception | The exception that triggered the error response (if applicable). |
from ResponseTrait |
| static protected array | $macros | The registered string macros. |
from Macroable |
Methods
Set a header on the Response.
Add an array of headers to the response.
Remove a header(s) from the response.
Expire a cookie when sending the response.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new JSON response instance.
Create an instance from a JSON string.
Set the JSONP callback.
Get the decoded JSON data from the response.
Set the data to be sent as JSON.
Determine if an error occurred during JSON encoding.
Set the JSON encoding options.
Determine if a JSON encoding option is set.
Flush all static state.
Details
in
ResponseTrait at line 26
int
status()
Get the status code for the response.
in
ResponseTrait at line 34
string
statusText()
Get the status text for the response.
in
ResponseTrait at line 42
string
content()
Get the content of the response.
in
ResponseTrait at line 50
mixed
getOriginalContent()
Get the original response content.
in
ResponseTrait at line 62
ResponseTrait
header(string $key, array|string $values, bool $replace = true)
Set a header on the Response.
in
ResponseTrait at line 74
ResponseTrait
withHeaders(HeaderBag|array $headers)
Add an array of headers to the response.
in
ResponseTrait at line 92
ResponseTrait
withoutHeader(array|string $key)
Remove a header(s) from the response.
in
ResponseTrait at line 106
ResponseTrait
cookie(mixed $cookie)
Add a cookie to the response.
in
ResponseTrait at line 116
ResponseTrait
withCookie(mixed $cookie)
Add a cookie to the response.
in
ResponseTrait at line 132
ResponseTrait
withoutCookie(mixed $cookie, string|null $path = null, string|null $domain = null)
Expire a cookie when sending the response.
in
ResponseTrait at line 146
string|null
getCallback()
Get the callback of the response.
in
ResponseTrait at line 156
ResponseTrait
withException(Throwable $e)
Set the exception to attach to the response.
in
ResponseTrait at line 168
never
throwResponse()
Throw the response in a HttpResponseException instance.
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 24
__construct(mixed $data = null, int $status = 200, array $headers = [], int $options = 0, bool $json = false)
Create a new JSON response instance.
at line 34
static JsonResponse
fromJsonString(string|null $data = null, int $status = 200, array $headers = [])
Create an instance from a JSON string.
at line 43
JsonResponse
withCallback(string|null $callback = null)
Set the JSONP callback.
at line 51
mixed
getData(bool $assoc = false, int $depth = 512)
Get the decoded JSON data from the response.
at line 61
JsonResponse
setData($data = [])
Set the data to be sent as JSON.
at line 86
protected bool
hasValidJson(int $jsonError)
Determine if an error occurred during JSON encoding.
at line 103
JsonResponse
setEncodingOptions($options)
Set the JSON encoding options.
at line 114
bool
hasEncodingOption(int $option)
Determine if a JSON encoding option is set.
at line 122
static void
flushState()
Flush all static state.