Comments (6)
Hey. Do you have doctrine/dbal installed?
from scramble.
Hey. Do you have doctrine/dbal installed?
Yes, all installed ( "doctrine/dbal": "^3.6",
) For it to work I'm having to do this within my code:
public function toArray($request): array {
return [
'success' => (bool) $this->success,
];
}
from scramble.
@jcsix694 can you show your resource's toArray
impleentation?
from scramble.
@romalytvynenko Here it is.
<?php
namespace App\Api\Resources;
use App\Api\Models\GameModel;
use App\Api\Models\UploadCollaboratorModel;
use App\Api\Models\UploadTypeModel;
use App\Api\Models\UploadVersionModel;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property string $name
* @property string $uuid
* @property string $description
* @property string $mini_description
* @property string $video_url
* @property int $views
* @property int $downloads
* @property int $hearts
* @property boolean $nsfw
* @property boolean $drm
* @property array $tags
* @property UploadCollaboratorModel $collaborator
* @property UploadTypeModel $type
* @property UploadVersionModel $version
* @property GameModel $game
* @property string $image_thumbnail
* @property string $image_main
* @property string $image_secondary
*/
class UploadResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param Request $request
* @return array
*/
public function toArray($request): array {
$collaborators = $this->collaborator->map(function ($collaborator) {
return new UserProfileResource($collaborator->userProfile);
});
$versions = $this->version->map(function ($version) {
return new UploadVersionResource($version);
});
$games = $this->game->map(function ($uploadGame) {
return new GameResource($uploadGame->game);
});
$stats = (object) [
'views' => $this->views,
'hearts' => $this->hearts,
'downloads' => $this->downloads
];
$images = [
'thumbnail' => $this->image_thumbnail ? (env('AWS_S3_URL') . '/' . env('AWS_BUCKET') . '/' . $this->image_thumbnail) : null,
'main' => $this->image_main ? (env('AWS_S3_URL') . '/' . env('AWS_BUCKET') . '/' . $this->image_main) : null,
'secondary' => $this->image_secondary ? (env('AWS_S3_URL') . '/' . env('AWS_BUCKET') . '/' . $this->image_secondary) : null,
];
return [
'uuid' => $this->uuid,
'name' => $this->name,
'description' => $this->description,
'miniDescription' => $this->mini_description,
'nsfw' => $this->nsfw,
'videoUrl' => $this->video_url,
'tags' => $this->tags,
'games' => $games,
'type' => new UploadTypeResource($this->type),
'collaborators' => $collaborators,
'versions' => $versions,
'drm' => $this->drm,
'stats' => $stats,
'images' => $images
];
}
}
from scramble.
Oh, gotcha. You need to hint resource type for Scramble by using mixin or property annotation.
https://scramble.dedoc.co/usage/response#model-resolution
from scramble.
Thanks for your help @romalytvynenko
from scramble.
Related Issues (20)
- AuthorizationException for form requests without any authorize method
- Route with optional parameter doesn't work HOT 2
- PHP8.2 issues
- Installation issue HOT 1
- Ressource Array-KeyConstants are not validated HOT 1
- Have an error Target [\Illuminate\Database\Eloquent\Model] is not instantiable. HOT 3
- Multiple files in array (Content-Type: multipart/form-data)
- OpenAPI Links parameter support
- Add @example for response types HOT 8
- "No response" returns invalid openapi spec HOT 2
- Deprecated methods error
- Error when grouping routes by tags: Undefined array key 0
- MethodReflector on buffer method HOT 2
- When extending Resources and using parent::toArray, Docs are returning string. HOT 1
- auth:sanctum is not detected or documented? HOT 7
- Error when analyzing route with non-existing model
- Cannot generate request documentation: Call to undefined method App\Models\User::setMethod()
- Attempt to read property "methods" on null HOT 11
- php 8.2 and laravel 10. php-parser version 5 not compatible HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scramble.