W3cubDocs

/Laravel 8

Response

class Response implements ArrayAccess (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable
protected ResponseInterface $response The underlying PSR response.
protected array $decoded The decoded JSON response.

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 proxy other methods to the underlying response.

void __construct(MessageInterface $response)

Create a new response instance.

string body()

Get the body of the response.

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

Get the JSON decoded body of the response as an array or scalar value.

object object()

Get the JSON decoded body of the response as an object.

string header(string $header)

Get a header from the response.

array headers()

Get the headers from the response.

int status()

Get the status code of the response.

UriInterface effectiveUri()

Get the effective URI of the response.

bool successful()

Determine if the request was successful.

bool ok()

Determine if the response code was "OK".

bool redirect()

Determine if the response was a redirect.

bool failed()

Determine if the response indicates a client or server error occurred.

bool clientError()

Determine if the response indicates a client error occurred.

bool serverError()

Determine if the response indicates a server error occurred.

$this onError(callable $callback)

Execute the given callback if there was a server or client error.

CookieJar cookies()

Get the response cookies.

ResponseInterface toPsrResponse()

Get the underlying PSR response for the response.

$this throw()

Throw an exception if a server or client error occurred.

bool offsetExists(string $offset)

Determine if the given offset exists.

mixed offsetGet(string $offset)

Get the value for a given offset.

void offsetSet(string $offset, mixed $value)

Set the value at the given offset.

void offsetUnset(string $offset)

Unset the value at the given offset.

string __toString()

Get the body of the response.

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 proxy other methods to the underlying response.

Parameters

string $method
array $parameters

Return Value

mixed

void __construct(MessageInterface $response)

Create a new response instance.

Parameters

MessageInterface $response

Return Value

void

string body()

Get the body of the response.

Return Value

string

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

Get the JSON decoded body of the response as an array or scalar value.

Parameters

string|null $key
mixed $default

Return Value

mixed

object object()

Get the JSON decoded body of the response as an object.

Return Value

object

string header(string $header)

Get a header from the response.

Parameters

string $header

Return Value

string

array headers()

Get the headers from the response.

Return Value

array

int status()

Get the status code of the response.

Return Value

int

UriInterface effectiveUri()

Get the effective URI of the response.

Return Value

UriInterface

bool successful()

Determine if the request was successful.

Return Value

bool

bool ok()

Determine if the response code was "OK".

Return Value

bool

bool redirect()

Determine if the response was a redirect.

Return Value

bool

bool failed()

Determine if the response indicates a client or server error occurred.

Return Value

bool

bool clientError()

Determine if the response indicates a client error occurred.

Return Value

bool

bool serverError()

Determine if the response indicates a server error occurred.

Return Value

bool

$this onError(callable $callback)

Execute the given callback if there was a server or client error.

Parameters

callable $callback

Return Value

$this

CookieJar cookies()

Get the response cookies.

Return Value

CookieJar

ResponseInterface toPsrResponse()

Get the underlying PSR response for the response.

Return Value

ResponseInterface

$this throw()

Throw an exception if a server or client error occurred.

Return Value

$this

Exceptions

RequestException

bool offsetExists(string $offset)

Determine if the given offset exists.

Parameters

string $offset

Return Value

bool

mixed offsetGet(string $offset)

Get the value for a given offset.

Parameters

string $offset

Return Value

mixed

void offsetSet(string $offset, mixed $value)

Set the value at the given offset.

Parameters

string $offset
mixed $value

Return Value

void

Exceptions

LogicException

void offsetUnset(string $offset)

Unset the value at the given offset.

Parameters

string $offset

Return Value

void

Exceptions

LogicException

string __toString()

Get the body of the response.

Return Value

string

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