GithubHelp home page GithubHelp logo

Comments (6)

romalytvynenko avatar romalytvynenko commented on August 18, 2024

Hey. Do you have doctrine/dbal installed?

from scramble.

jcsix694 avatar jcsix694 commented on August 18, 2024

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.

romalytvynenko avatar romalytvynenko commented on August 18, 2024

@jcsix694 can you show your resource's toArray impleentation?

from scramble.

jcsix694 avatar jcsix694 commented on August 18, 2024

@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.

romalytvynenko avatar romalytvynenko commented on August 18, 2024

Oh, gotcha. You need to hint resource type for Scramble by using mixin or property annotation.

https://scramble.dedoc.co/usage/response#model-resolution

image

from scramble.

jcsix694 avatar jcsix694 commented on August 18, 2024

Thanks for your help @romalytvynenko

from scramble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.