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

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
encodeBigIntegersWhenEnabled(mixed $value)

Wrap big integers only when this response opted in.

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.

array
encodeBigIntegersInArray(array $value, SplObjectStorage|null $seen)

Wrap the big integers held by the given array.

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.

bool
hasPlainJsonRepresentation(object $value)

Determine if the object's public properties are what json_encode emits.

__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.

preserveBigIntegers(bool $preserve = true)

Preserve integers outside JavaScript's safe range as BigInt values.

with(array|ProvidesInertiaProperties|int|string $key, mixed $value = null)

Add additional properties to the page.

withViewData(array|string $key, mixed $value = null)

Add additional data to the view.

rootView(string $rootView)

Set the root view.

flash(BackedEnum|UnitEnum|string|array $key, mixed $value = null)

Add flash data to the response.

Response
toResponse(Request $request)

Create an HTTP response that represents the object.

array
resolveClearHistory(Request $request)

Resolve the clear history flag.

array
resolveEncryptHistory(Request $request)

Resolve the encrypt history flag.

array
resolveFlashData(Request $request)

Resolve flash data from the session.

array
resolvePreserveBigIntegers(Request $request)

Resolve the preserve big integers flag.

array
resolvePreserveFragment(Request $request)

Resolve the preserve fragment flag from the session.

string
getUrl(Request $request)

Get the URL from the request while preserving the trailing slash.

string
finishUrlWithTrailingSlash(string $url)

Ensure the URL has a trailing slash before the query string.

static void
flushState()

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.

Parameters

string $name
callable|object $macro

Return Value

void

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.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

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.

Return Value

void

in Macroable at line 83
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 108
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

protected mixed encodeBigIntegersWhenEnabled(mixed $value)

Wrap big integers only when this response opted in.

Parameters

mixed $value

Return Value

mixed

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.

Parameters

mixed $value
SplObjectStorage|null $seen

Return Value

mixed

protected array encodeBigIntegersInArray(array $value, SplObjectStorage|null $seen)

Wrap the big integers held by the given array.

Parameters

array $value
SplObjectStorage|null $seen

Return Value

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.

Parameters

object $value
SplObjectStorage $seen

Return Value

mixed

in PreservesBigIntegers at line 145
protected bool hasPlainJsonRepresentation(object $value)

Determine if the object's public properties are what json_encode emits.

Parameters

object $value

Return Value

bool

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.

Parameters

string $component
array $sharedProps
array $props
string $rootView
string $version
bool $encryptHistory
Closure|null $urlResolver
bool $preserveBigIntegers

at line 116
Response preserveBigIntegers(bool $preserve = true)

Preserve integers outside JavaScript's safe range as BigInt values.

Parameters

bool $preserve

Return Value

Response

at line 129
Response with(array|ProvidesInertiaProperties|int|string $key, mixed $value = null)

Add additional properties to the page.

Parameters

array|ProvidesInertiaProperties|int|string $key
mixed $value

Return Value

Response

at line 148
Response withViewData(array|string $key, mixed $value = null)

Add additional data to the view.

Parameters

array|string $key
mixed $value

Return Value

Response

at line 164
Response rootView(string $rootView)

Set the root view.

Parameters

string $rootView

Return Value

Response

at line 177
Response flash(BackedEnum|UnitEnum|string|array $key, mixed $value = null)

Add flash data to the response.

Parameters

BackedEnum|UnitEnum|string|array $key
mixed $value

Return Value

Response

at line 187
Response toResponse(Request $request)

Create an HTTP response that represents the object.

Parameters

Request $request

Return Value

Response

at line 229
protected array resolveClearHistory(Request $request)

Resolve the clear history flag.

Parameters

Request $request

Return Value

array

at line 239
protected array resolveEncryptHistory(Request $request)

Resolve the encrypt history flag.

Parameters

Request $request

Return Value

array

at line 249
protected array resolveFlashData(Request $request)

Resolve flash data from the session.

Parameters

Request $request

Return Value

array

at line 265
protected array resolvePreserveBigIntegers(Request $request)

Resolve the preserve big integers flag.

Parameters

Request $request

Return Value

array

at line 275
protected array resolvePreserveFragment(Request $request)

Resolve the preserve fragment flag from the session.

Parameters

Request $request

Return Value

array

at line 283
protected string getUrl(Request $request)

Get the URL from the request while preserving the trailing slash.

Parameters

Request $request

Return Value

string

at line 299
protected string finishUrlWithTrailingSlash(string $url)

Ensure the URL has a trailing slash before the query string.

Parameters

string $url

Return Value

string

at line 312
static void flushState()

Flush all static state.

Return Value

void