Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 20, 2024
1 parent 2fc776d commit 70c6fbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
40 changes: 23 additions & 17 deletions src/Illuminate/Http/Resources/Json/JsonResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ class JsonResource implements ArrayAccess, JsonSerializable, Responsable, UrlRou
*/
public $additional = [];

/**
* The instance level wrapper configured for the resource.
*
* @var string|null
*/
public $wrapper = null;

/**
* The "data" wrapper that should be applied.
*
* @var string|null
*/
public static $wrap = 'data';

public ?string $wrapper = null;

/**
* Create a new resource instance.
*
Expand Down Expand Up @@ -207,44 +212,45 @@ public function withResponse(Request $request, JsonResponse $response)
/**
* Set the string that should wrap the outer-most resource array.
*
* @param string $value
* @return void
* @param string|null $value
* @return $this
*/
public static function wrap($value)
public function withWrapper(?string $value)
{
static::$wrap = $value;
$this->wrapper = $value;

return $this;
}

/**
* Set the string that should wrap the outer-most resource array.
* Disable wrapping of the outer-most resource array.
*
* @return $this
*/
public function withWrapper(?string $value): static
public function withoutWrapper()
{
$this->wrapper = $value;

return $this;
return $this->withWrapper(null);
}

/**
* Disable wrapping of the outer-most resource array.
* Set the string that should wrap the outer-most resource array.
*
* @param string $value
* @return void
*/
public static function withoutWrapping()
public static function wrap($value)
{
static::$wrap = null;
static::$wrap = $value;
}

/**
* Disable wrapping of the outer-most resource array.
*
* @return $this
* @return void
*/
public function withoutWrapper(): static
public static function withoutWrapping()
{
return $this->withWrapper(null);
static::$wrap = null;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Illuminate/Http/Resources/Json/ResourceResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ protected function haveAdditionalInformationAndDataIsUnwrapped($data, $with, $ad
*/
protected function wrapper()
{
if ($this->resource instanceof JsonResource) {
return $this->resource->wrapper;
}

return get_class($this->resource)::$wrap;
return $this->resource instanceof JsonResource
? $this->resource->wrapper
: get_class($this->resource)::$wrap;
}

/**
Expand Down

0 comments on commit 70c6fbe

Please sign in to comment.