Response
class Response implements Responsable
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected bool | $preserveBigIntegers | Indicates if integers outside JavaScript's safe range should be preserved. |
from PreservesBigIntegers |
| static protected array<class-string, bool> | $plainJsonClasses | Whether each encountered class serializes as its public properties. |
from PreservesBigIntegers |
| protected string | $component | The name of the root component. |
|
| protected array<array-key, mixed|ProvidesInertiaProperties> | $props | The page props. |
|
| protected string | $rootView | The name of the root view. |
|
| protected string | $version | The asset version. |
|
| protected bool | $clearHistory | Indicates if the browser history should be cleared. |
|
| protected bool | $preserveFragment | Indicates if the URL fragment should be preserved across redirects. |
|
| protected bool | $encryptHistory | Indicates if the browser history should be encrypted. |
|
| protected array<string, mixed> | $viewData | The view data. |
|
| protected Closure|null | $urlResolver | The URL resolver callback. |
|
| protected array<array-key, mixed|ProvidesInertiaProperties> | $sharedProps | The shared properties (before merge with page props). |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Wrap big integers only when this response opted in.
Wrap integers outside JavaScript's safe integer range as a marker so the frontend can revive them as native BigInt values without losing precision when the JSON response is parsed.
Wrap the big integers held by the given array.
Wrap the big integers held by the given object, unwrapping it the same way json_encode would so the shape it emits is unchanged. Objects are cast back so they keep serializing as a JSON object, not an array.
Determine if the object's public properties are what json_encode emits.
Create a new Inertia response instance.
Preserve integers outside JavaScript's safe range as BigInt values.
Add additional properties to the page.
Add additional data to the view.
Add flash data to the response.
Ensure the URL has a trailing slash before the query string.
Flush all static state.
Details
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
PreservesBigIntegers at line 43
protected mixed
encodeBigIntegersWhenEnabled(mixed $value)
Wrap big integers only when this response opted in.
in
PreservesBigIntegers at line 55
protected mixed
encodeBigIntegers(mixed $value, SplObjectStorage|null $seen = null)
Wrap integers outside JavaScript's safe integer range as a marker so the frontend can revive them as native BigInt values without losing precision when the JSON response is parsed.
in
PreservesBigIntegers at line 96
protected array
encodeBigIntegersInArray(array $value, SplObjectStorage|null $seen)
Wrap the big integers held by the given array.
in
PreservesBigIntegers at line 116
protected mixed
encodeBigIntegersInObject(object $value, SplObjectStorage $seen)
Wrap the big integers held by the given object, unwrapping it the same way json_encode would so the shape it emits is unchanged. Objects are cast back so they keep serializing as a JSON object, not an array.
in
PreservesBigIntegers at line 145
protected bool
hasPlainJsonRepresentation(object $value)
Determine if the object's public properties are what json_encode emits.
at line 89
__construct(string $component, array $sharedProps, array $props, string $rootView = 'app', string $version = '', bool $encryptHistory = false, Closure|null $urlResolver = null, bool $preserveBigIntegers = false)
Create a new Inertia response instance.
at line 116
Response
preserveBigIntegers(bool $preserve = true)
Preserve integers outside JavaScript's safe range as BigInt values.
at line 129
Response
with(array|ProvidesInertiaProperties|int|string $key, mixed $value = null)
Add additional properties to the page.
at line 148
Response
withViewData(array|string $key, mixed $value = null)
Add additional data to the view.
at line 164
Response
rootView(string $rootView)
Set the root view.
at line 177
Response
flash(BackedEnum|UnitEnum|string|array $key, mixed $value = null)
Add flash data to the response.
at line 187
Response
toResponse(Request $request)
Create an HTTP response that represents the object.
at line 229
protected array
resolveClearHistory(Request $request)
Resolve the clear history flag.
at line 239
protected array
resolveEncryptHistory(Request $request)
Resolve the encrypt history flag.
at line 249
protected array
resolveFlashData(Request $request)
Resolve flash data from the session.
at line 265
protected array
resolvePreserveBigIntegers(Request $request)
Resolve the preserve big integers flag.
at line 275
protected array
resolvePreserveFragment(Request $request)
Resolve the preserve fragment flag from the session.
at line 283
protected string
getUrl(Request $request)
Get the URL from the request while preserving the trailing slash.
at line 299
protected string
finishUrlWithTrailingSlash(string $url)
Ensure the URL has a trailing slash before the query string.
at line 312
static void
flushState()
Flush all static state.