-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Avoid constructor call when fetching resource JSON options (#40261
) * Avoid constructor call when fetching json options * Update CollectsResources.php * Update CollectsResources.php Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
8c293f9
commit 424f97a
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/Integration/Http/Fixtures/PostResourceWithJsonOptionsAndTypeHints.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Http\Fixtures; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class PostResourceWithJsonOptionsAndTypeHints extends JsonResource | ||
{ | ||
public function __construct(Post $resource) | ||
{ | ||
parent::__construct($resource); | ||
} | ||
|
||
public function toArray($request) | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'title' => $this->title, | ||
'reading_time' => $this->reading_time, | ||
]; | ||
} | ||
|
||
public function jsonOptions() | ||
{ | ||
return JSON_PRESERVE_ZERO_FRACTION; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters