class ResponseFactory

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable

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.

void
setRootView(string $name)

Set the root view template for Inertia responses. This template serves as the HTML wrapper that contains the Inertia root element where the frontend application will be mounted.

void
share(mixed $key, mixed $value = null)

Share data across all Inertia responses. This data is automatically included with every response, making it ideal for user authentication state, flash messages, etc.

mixed
getShared(string|null $key = null, mixed $default = null)

Get the shared data for a given key. Returns all shared data if no key is provided, or the value for a specific key with an optional default fallback.

void
flushShared()

Flush all shared data.

void
version(Closure|string|null $version)

Set the asset version.

string
getVersion()

Get the asset version.

void
resolveUrlUsing(Closure|null $urlResolver = null)

Set the URL resolver.

void
transformComponentUsing(Closure|null $componentTransformer = null)

Set the component transformer.

void
clearHistory()

Clear the browser history on the next visit.

void
preserveFragment()

Preserve the URL fragment across the next redirect.

void
encryptHistory(bool $encrypt = true)

Encrypt the browser history.

void
disableSsr(Closure|bool $condition = true)

Disable server-side rendering, optionally based on a condition.

void
withoutSsr(array|string $paths)

Exclude the given paths from server-side rendering.

void
configureSsrRequestUsing(Closure|null $callback = null)

Configure the HTTP request that is sent to the SSR server.

optional(callable $callback)

Create an optional property.

defer(callable $callback, string $group = 'default', bool $rescue = false)

Create a deferred property.

merge(mixed $value)

Create a merge property.

deepMerge(mixed $value)

Create a deep merge property.

always(mixed $value)

Create an always property.

scroll(mixed $value, string $wrapper = 'data', ProvidesScrollMetadata|callable|null $metadata = null)

Create a scroll property.

live(mixed $value, array|object|string|null $on = null, array|Channel|string|null $channel = null, int|null $throttle = null)

Create a live property.

once(callable $value)

Create a once property.

shareOnce(string $key, callable $callback)

Create and share a once property.

void
findComponentOrFail(string $component)

Find the component or fail.

mixed
transformComponent(mixed $component)

Transform the component name.

render(mixed $component, mixed $props = [])

Create an Inertia response.

array
broadcastProps(array $props)

Resolve props for a broadcast payload.

Response
location(string|RedirectResponse $url)

Create an Inertia location response.

void
handleExceptionsUsing(callable $callback)

Register a callback to handle HTTP exceptions for Inertia requests.

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

Flash data to be included with the next response. Unlike regular props, flash data is not persisted in the browser's history state, making it ideal for one-time notifications like toasts or highlights.

back(int $status = 302, array $headers = [], bool|string $fallback = false)

Create a new redirect response to the previous location.

array
getFlashed(Request|null $request = null)

Retrieve the flashed data from the session.

array
pullFlashed(Request|null $request = null)

Retrieve and remove the flashed data from the session.

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

at line 54
void setRootView(string $name)

Set the root view template for Inertia responses. This template serves as the HTML wrapper that contains the Inertia root element where the frontend application will be mounted.

Parameters

string $name

Return Value

void

at line 66
void share(mixed $key, mixed $value = null)

Share data across all Inertia responses. This data is automatically included with every response, making it ideal for user authentication state, flash messages, etc.

Parameters

mixed $key
mixed $value

Return Value

void

at line 90
mixed getShared(string|null $key = null, mixed $default = null)

Get the shared data for a given key. Returns all shared data if no key is provided, or the value for a specific key with an optional default fallback.

Parameters

string|null $key
mixed $default

Return Value

mixed

at line 104
void flushShared()

Flush all shared data.

Return Value

void

at line 115
void version(Closure|string|null $version)

Set the asset version.

Parameters

Closure|string|null $version

Return Value

void

at line 123
string getVersion()

Get the asset version.

Return Value

string

at line 137
void resolveUrlUsing(Closure|null $urlResolver = null)

Set the URL resolver.

Parameters

Closure|null $urlResolver

Return Value

void

at line 145
void transformComponentUsing(Closure|null $componentTransformer = null)

Set the component transformer.

Parameters

Closure|null $componentTransformer

Return Value

void

at line 153
void clearHistory()

Clear the browser history on the next visit.

Return Value

void

at line 161
void preserveFragment()

Preserve the URL fragment across the next redirect.

Return Value

void

at line 169
void encryptHistory(bool $encrypt = true)

Encrypt the browser history.

Parameters

bool $encrypt

Return Value

void

at line 177
void disableSsr(Closure|bool $condition = true)

Disable server-side rendering, optionally based on a condition.

Parameters

Closure|bool $condition

Return Value

void

at line 193
void withoutSsr(array|string $paths)

Exclude the given paths from server-side rendering.

Parameters

array|string $paths

Return Value

void

at line 207
void configureSsrRequestUsing(Closure|null $callback = null)

Configure the HTTP request that is sent to the SSR server.

Parameters

Closure|null $callback

Return Value

void

at line 221
OptionalProp optional(callable $callback)

Create an optional property.

Parameters

callable $callback

Return Value

OptionalProp

at line 229
DeferProp defer(callable $callback, string $group = 'default', bool $rescue = false)

Create a deferred property.

Parameters

callable $callback
string $group
bool $rescue

Return Value

DeferProp

at line 237
MergeProp merge(mixed $value)

Create a merge property.

Parameters

mixed $value

Return Value

MergeProp

at line 245
MergeProp deepMerge(mixed $value)

Create a deep merge property.

Parameters

mixed $value

Return Value

MergeProp

at line 253
AlwaysProp always(mixed $value)

Create an always property.

Parameters

mixed $value

Return Value

AlwaysProp

at line 266
ScrollProp scroll(mixed $value, string $wrapper = 'data', ProvidesScrollMetadata|callable|null $metadata = null)

Create a scroll property.

Parameters

mixed $value
string $wrapper
ProvidesScrollMetadata|callable|null $metadata

Return Value

ScrollProp

at line 277
LiveProp live(mixed $value, array|object|string|null $on = null, array|Channel|string|null $channel = null, int|null $throttle = null)

Create a live property.

Parameters

mixed $value
array|object|string|null $on
array|Channel|string|null $channel
int|null $throttle

Return Value

LiveProp

at line 285
OnceProp once(callable $value)

Create a once property.

Parameters

callable $value

Return Value

OnceProp

at line 293
OnceProp shareOnce(string $key, callable $callback)

Create and share a once property.

Parameters

string $key
callable $callback

Return Value

OnceProp

at line 303
protected void findComponentOrFail(string $component)

Find the component or fail.

Parameters

string $component

Return Value

void

Exceptions

ComponentNotFoundException

at line 315
protected mixed transformComponent(mixed $component)

Transform the component name.

Parameters

mixed $component

Return Value

mixed

at line 332
Response render(mixed $component, mixed $props = [])

Create an Inertia response.

Parameters

mixed $component
mixed $props

Return Value

Response

at line 381
array broadcastProps(array $props)

Resolve props for a broadcast payload.

Parameters

array $props

Return Value

array

at line 395
Response location(string|RedirectResponse $url)

Create an Inertia location response.

Parameters

string|RedirectResponse $url

Return Value

Response

at line 410
void handleExceptionsUsing(callable $callback)

Register a callback to handle HTTP exceptions for Inertia requests.

The callback is stored on the exception handler singleton and applies to all requests for the worker lifetime.

Parameters

callable $callback

Return Value

void

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

Flash data to be included with the next response. Unlike regular props, flash data is not persisted in the browser's history state, making it ideal for one-time notifications like toasts or highlights.

Parameters

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

Return Value

ResponseFactory

at line 478
RedirectResponse back(int $status = 302, array $headers = [], bool|string $fallback = false)

Create a new redirect response to the previous location.

Parameters

int $status
array $headers
bool|string $fallback

Return Value

RedirectResponse

at line 488
array getFlashed(Request|null $request = null)

Retrieve the flashed data from the session.

Parameters

Request|null $request

Return Value

array

at line 500
array pullFlashed(Request|null $request = null)

Retrieve and remove the flashed data from the session.

Parameters

Request|null $request

Return Value

array

at line 510
static void flushState()

Flush all static state.

Return Value

void