GithubHelp home page GithubHelp logo

Comments (4)

romalytvynenko avatar romalytvynenko commented on August 18, 2024 1

@antonhedling

Awesome, thank you so much! Fix is on the way. This is exactly the problem.

Will ping you here once done.

from scramble.

romalytvynenko avatar romalytvynenko commented on August 18, 2024 1

Hey @antonhedling

Just released 0.3.0, please update: https://github.com/dedoc/scramble/releases/tag/v0.3.0

The issue should be fixed.

Thanks for your time and reporting the issue.

from scramble.

romalytvynenko avatar romalytvynenko commented on August 18, 2024

Hey @antonhedling!

Thanks for reporting!

If you found an endpoint causing this, can you please send me more code?

  1. Full resource class' source (both SchoolResource and the resource which contains schools)
  2. Full controller class (or, at least, a method code)

This should be a good point for me to start.

Thanks!

from scramble.

antonhedling avatar antonhedling commented on August 18, 2024

Okay, I did just now find out the line that is causing this, so it looks like this isn't necessarily connected to $this->whenLoaded().

It's when two resources cross-reference one another:

AreaResource.php

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class AreaResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'subareas' => $this->subareas,
            'schools' => SchoolResource::collection($this->whenLoaded('schools')),
        ];
    }
}

SchoolResource.php

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class SchoolResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'area' => new AreaResource($this->area),
        ];
    }
}

If I remove the AreaResource there, it works again.

I mean sure, you can argue that resources shouldn't look like this. But it would be great if we could prevent whatever infinite loop is caused here.

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.