class Illuminate / Http / Resources / Json / JsonResource
You are viewing an older version of the documentation. For the latest, please visit master documentation.

JsonResource

Implements

Uses

Properties

public

$resource mixed

The resource instance.

Default: null
public

$with array

The additional data that should be added to the top-level resource array.

Default: []
public

$additional array

The additional meta data that should be added to the resource response.

Added during response construction by the developer.

Default: []
public static

$wrap string|null

The "data" wrapper that should be applied.

Default: 'data'

Methods

public

__construct ( $resource ) : void

Create a new resource instance.

Parameters

  • $resource mixed
public static

make ( $parameters ) : static

Create a new resource instance.

Parameters

  • $parameters mixed
public static

collection ( $resource ) : AnonymousResourceCollection

Create a new anonymous resource collection.

Parameters

  • $resource mixed
public

resolve ( $request ) : array

Resolve the resource to an array.

Parameters

public

toArray ( $request ) : array|Arrayable |JsonSerializable

Transform the resource into an array.

Parameters

public

toJson ( $options ) : string

Convert the model instance to JSON.

Parameters

  • $options int
public

with ( $request ) : array

Get any additional data that should be returned with the resource array.

Parameters

public

additional ( array $data ) : $this

Add additional meta data to the resource response.

Parameters

  • $data array
public

jsonOptions ( ) : int

Get the JSON serialization options that should be applied to the resource response.

public

withResponse ( $request , $response ) : void

Customize the response for a request.

Parameters

public static

wrap ( $value ) : void

Set the string that should wrap the outer-most resource array.

Parameters

  • $value string
public static

withoutWrapping ( ) : void

Disable wrapping of the outer-most resource array.

public

response ( $request ) : JsonResponse

Transform the resource into an HTTP response.

Parameters

public

toResponse ( $request ) : JsonResponse

Create an HTTP response that represents the object.

Parameters

public

jsonSerialize ( ) : array

Prepare the resource for JSON serialization.