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.

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.

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.

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.

RedirectResponse
back(int $status = 302, array $headers = [], mixed $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 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 50
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 62
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 82
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 96
void flushShared()

Flush all shared data.

Return Value

void

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

Set the asset version.

Parameters

Closure|string|null $version

Return Value

void

at line 112
string getVersion()

Get the asset version.

Return Value

string

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

Set the URL resolver.

Parameters

Closure|null $urlResolver

Return Value

void

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

Set the component transformer.

Parameters

Closure|null $componentTransformer

Return Value

void

at line 142
void clearHistory()

Clear the browser history on the next visit.

Return Value

void

at line 150
void preserveFragment()

Preserve the URL fragment across the next redirect.

Return Value

void

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

Encrypt the browser history.

Parameters

bool $encrypt

Return Value

void

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

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

Parameters

Closure|bool $condition

Return Value

void

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

Exclude the given paths from server-side rendering.

Parameters

array|string $paths

Return Value

void

at line 196
OptionalProp optional(callable $callback)

Create an optional property.

Parameters

callable $callback

Return Value

OptionalProp

at line 204
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 212
MergeProp merge(mixed $value)

Create a merge property.

Parameters

mixed $value

Return Value

MergeProp

at line 220
MergeProp deepMerge(mixed $value)

Create a deep merge property.

Parameters

mixed $value

Return Value

MergeProp

at line 228
AlwaysProp always(mixed $value)

Create an always property.

Parameters

mixed $value

Return Value

AlwaysProp

at line 241
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 249
OnceProp once(callable $value)

Create a once property.

Parameters

callable $value

Return Value

OnceProp

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

Create and share a once property.

Parameters

string $key
callable $callback

Return Value

OnceProp

at line 267
protected void findComponentOrFail(string $component)

Find the component or fail.

Parameters

string $component

Return Value

void

Exceptions

ComponentNotFoundException

at line 279
protected mixed transformComponent(mixed $component)

Transform the component name.

Parameters

mixed $component

Return Value

mixed

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

Create an Inertia response.

Parameters

mixed $component
mixed $props

Return Value

Response

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

Create an Inertia location response.

Parameters

string|RedirectResponse $url

Return Value

Response

at line 352
void handleExceptionsUsing(callable $callback)

Register a callback to handle HTTP exceptions for Inertia requests.

Boot-only. 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 392
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 419
RedirectResponse back(int $status = 302, array $headers = [], mixed $fallback = false)

Create a new redirect response to the previous location.

Parameters

int $status
array $headers
mixed $fallback

Return Value

RedirectResponse

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

Retrieve the flashed data from the session.

Parameters

Request|null $request

Return Value

array

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

Retrieve and remove the flashed data from the session.

Parameters

Request|null $request

Return Value

array

at line 451
static void flushState()

Flush all static state.

Return Value

void