ResponseFactory
class ResponseFactory
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
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.
Share data across all Inertia responses. This data is automatically included with every response, making it ideal for user authentication state, flash messages, etc.
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.
Flush all shared data.
Get the asset version.
Clear the browser history on the next visit.
Preserve the URL fragment across the next redirect.
Encrypt the browser history.
Disable server-side rendering, optionally based on a condition.
Exclude the given paths from server-side rendering.
Create an optional property.
Create a deferred property.
Create an always property.
Create a scroll property.
Find the component or fail.
Transform the component name.
Create an Inertia location response.
Register a callback to handle HTTP exceptions for Inertia requests.
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.
Create a new redirect response to the previous location.
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.
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.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
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.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
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.
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.
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.
at line 96
void
flushShared()
Flush all shared data.
at line 104
void
version(Closure|string|null $version)
Set the asset version.
at line 112
string
getVersion()
Get the asset version.
at line 126
void
resolveUrlUsing(Closure|null $urlResolver = null)
Set the URL resolver.
at line 134
void
transformComponentUsing(Closure|null $componentTransformer = null)
Set the component transformer.
at line 142
void
clearHistory()
Clear the browser history on the next visit.
at line 150
void
preserveFragment()
Preserve the URL fragment across the next redirect.
at line 158
void
encryptHistory(bool $encrypt = true)
Encrypt the browser history.
at line 166
void
disableSsr(Closure|bool $condition = true)
Disable server-side rendering, optionally based on a condition.
at line 182
void
withoutSsr(array|string $paths)
Exclude the given paths from server-side rendering.
at line 196
OptionalProp
optional(callable $callback)
Create an optional property.
at line 204
DeferProp
defer(callable $callback, string $group = 'default', bool $rescue = false)
Create a deferred property.
at line 212
MergeProp
merge(mixed $value)
Create a merge property.
at line 220
MergeProp
deepMerge(mixed $value)
Create a deep merge property.
at line 228
AlwaysProp
always(mixed $value)
Create an always property.
at line 241
ScrollProp
scroll(mixed $value, string $wrapper = 'data', ProvidesScrollMetadata|callable|null $metadata = null)
Create a scroll property.
at line 249
OnceProp
once(callable $value)
Create a once property.
at line 257
OnceProp
shareOnce(string $key, callable $callback)
Create and share a once property.
at line 267
protected void
findComponentOrFail(string $component)
Find the component or fail.
at line 279
protected mixed
transformComponent(mixed $component)
Transform the component name.
at line 296
Response
render(mixed $component, mixed $props = [])
Create an Inertia response.
at line 337
Response
location(string|RedirectResponse $url)
Create an Inertia location 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.
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.
at line 419
RedirectResponse
back(int $status = 302, array $headers = [], mixed $fallback = false)
Create a new redirect response to the previous location.
at line 429
array
getFlashed(Request|null $request = null)
Retrieve the flashed data from the session.
at line 441
array
pullFlashed(Request|null $request = null)
Retrieve and remove the flashed data from the session.
at line 451
static void
flushState()
Flush all static state.