W3cubDocs

/Laravel 8

ResponseFactory

class ResponseFactory implements ResponseFactory (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable
protected Factory $view The view factory instance.
protected Redirector $redirector The redirector instance.

Methods

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

Register a custom macro.

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

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

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

Dynamically handle calls to the class.

from Macroable
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
void __construct(Factory $view, Redirector $redirector)

Create a new response factory instance.

Response make(string $content = '', int $status = 200, array $headers = [])

Create a new response instance.

Response noContent(int $status = 204, array $headers = [])

Create a new "no content" response.

Response view(string|array $view, array $data = [], int $status = 200, array $headers = [])

Create a new response for a given view.

JsonResponse json(mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSON response instance.

JsonResponse jsonp(string $callback, mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSONP response instance.

StreamedResponse stream(Closure $callback, int $status = 200, array $headers = [])

Create a new streamed response instance.

StreamedResponse streamDownload(Closure $callback, string|null $name = null, array $headers = [], string|null $disposition = 'attachment')

Create a new streamed response instance as a file download.

BinaryFileResponse download(SplFileInfo|string $file, string|null $name = null, array $headers = [], string|null $disposition = 'attachment')

Create a new file download response.

string fallbackName(string $name)

Convert the string to ASCII characters that are equivalent to the given name.

BinaryFileResponse file(SplFileInfo|string $file, array $headers = [])

Return the raw contents of a binary file.

RedirectResponse redirectTo(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the given path.

RedirectResponse redirectToRoute(string $route, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a named route.

RedirectResponse redirectToAction(string $action, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a controller action.

RedirectResponse redirectGuest(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response, while putting the current URL in the session.

RedirectResponse redirectToIntended(string $default = '/', int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the previously intended location.

Details

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(Factory $view, Redirector $redirector)

Create a new response factory instance.

Parameters

Factory $view
Redirector $redirector

Return Value

void

Response make(string $content = '', int $status = 200, array $headers = [])

Create a new response instance.

Parameters

string $content
int $status
array $headers

Return Value

Response

Response noContent(int $status = 204, array $headers = [])

Create a new "no content" response.

Parameters

int $status
array $headers

Return Value

Response

Response view(string|array $view, array $data = [], int $status = 200, array $headers = [])

Create a new response for a given view.

Parameters

string|array $view
array $data
int $status
array $headers

Return Value

Response

JsonResponse json(mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSON response instance.

Parameters

mixed $data
int $status
array $headers
int $options

Return Value

JsonResponse

JsonResponse jsonp(string $callback, mixed $data = [], int $status = 200, array $headers = [], int $options = 0)

Create a new JSONP response instance.

Parameters

string $callback
mixed $data
int $status
array $headers
int $options

Return Value

JsonResponse

StreamedResponse stream(Closure $callback, int $status = 200, array $headers = [])

Create a new streamed response instance.

Parameters

Closure $callback
int $status
array $headers

Return Value

StreamedResponse

StreamedResponse streamDownload(Closure $callback, string|null $name = null, array $headers = [], string|null $disposition = 'attachment')

Create a new streamed response instance as a file download.

Parameters

Closure $callback
string|null $name
array $headers
string|null $disposition

Return Value

StreamedResponse

BinaryFileResponse download(SplFileInfo|string $file, string|null $name = null, array $headers = [], string|null $disposition = 'attachment')

Create a new file download response.

Parameters

SplFileInfo|string $file
string|null $name
array $headers
string|null $disposition

Return Value

BinaryFileResponse

protected string fallbackName(string $name)

Convert the string to ASCII characters that are equivalent to the given name.

Parameters

string $name

Return Value

string

BinaryFileResponse file(SplFileInfo|string $file, array $headers = [])

Return the raw contents of a binary file.

Parameters

SplFileInfo|string $file
array $headers

Return Value

BinaryFileResponse

RedirectResponse redirectTo(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the given path.

Parameters

string $path
int $status
array $headers
bool|null $secure

Return Value

RedirectResponse

RedirectResponse redirectToRoute(string $route, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a named route.

Parameters

string $route
mixed $parameters
int $status
array $headers

Return Value

RedirectResponse

RedirectResponse redirectToAction(string $action, mixed $parameters = [], int $status = 302, array $headers = [])

Create a new redirect response to a controller action.

Parameters

string $action
mixed $parameters
int $status
array $headers

Return Value

RedirectResponse

RedirectResponse redirectGuest(string $path, int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response, while putting the current URL in the session.

Parameters

string $path
int $status
array $headers
bool|null $secure

Return Value

RedirectResponse

RedirectResponse redirectToIntended(string $default = '/', int $status = 302, array $headers = [], bool|null $secure = null)

Create a new redirect response to the previously intended location.

Parameters

string $default
int $status
array $headers
bool|null $secure

Return Value

RedirectResponse

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Routing/ResponseFactory.html