class Response implements Responsable

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected string $component

The name of the root component.

protected array<string, mixed> $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.

__construct(string $component, array $sharedProps, array $props, string $rootView = 'app', string $version = '', bool $encryptHistory = false, Closure|null $urlResolver = null)

Create a new Inertia response instance.

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

Add additional properties to the page.

withViewData(array<string, mixed>|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
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 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.

Parameters

string $name
callable|object $macro

Return Value

void

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.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

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

Check if macro is registered.

Parameters

string $name

Return Value

bool

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.

Return Value

void

in Macroable at line 78
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 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 88
__construct(string $component, array $sharedProps, array $props, string $rootView = 'app', string $version = '', bool $encryptHistory = false, Closure|null $urlResolver = null)

Create a new Inertia response instance.

Parameters

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

at line 115
Response with(array<string, mixed>|ProvidesInertiaProperties|string $key, mixed $value = null)

Add additional properties to the page.

Parameters

array<string, mixed>|ProvidesInertiaProperties|string $key
mixed $value

Return Value

Response

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

Add additional data to the view.

Parameters

array<string, mixed>|string $key
mixed $value

Return Value

Response

at line 151
Response rootView(string $rootView)

Set the root view.

Parameters

string $rootView

Return Value

Response

at line 164
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 174
Response toResponse(Request $request)

Create an HTTP response that represents the object.

Parameters

Request $request

Return Value

Response

at line 207
protected array resolveClearHistory(Request $request)

Resolve the clear history flag.

Parameters

Request $request

Return Value

array

at line 217
protected array resolveEncryptHistory(Request $request)

Resolve the encrypt history flag.

Parameters

Request $request

Return Value

array

at line 227
protected array resolveFlashData(Request $request)

Resolve flash data from the session.

Parameters

Request $request

Return Value

array

at line 239
protected array resolvePreserveFragment(Request $request)

Resolve the preserve fragment flag from the session.

Parameters

Request $request

Return Value

array

at line 247
protected string getUrl(Request $request)

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

Parameters

Request $request

Return Value

string

at line 263
protected string finishUrlWithTrailingSlash(string $url)

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

Parameters

string $url

Return Value

string

at line 276
static void flushState()

Flush all static state.

Return Value

void