GithubHelp home page GithubHelp logo

Comments (8)

jonquintero avatar jonquintero commented on June 18, 2024

Sorry I saw that you are WIP in some issues...would be great have the links in the relationships

from json-api.

timacdonald avatar timacdonald commented on June 18, 2024

Hey! Lets see if we can debug this together.

First thing to check - are you calling JsonApiResource::minimalAttributes() anywhere?

Could you also please share with me the resources that aren't working for you?

from json-api.

jonquintero avatar jonquintero commented on June 18, 2024

Hi Tim, thank you for answer me

This is the resources
https://github.com/jonquintero/api-test-pest/blob/8593ed077c166a671aa3aaa9d1abe7c7901dd7de/app/Http/Resources/EmployeeResource.php#L1

from json-api.

jonquintero avatar jonquintero commented on June 18, 2024

if you see, I'm using 'department' => fn () => new DepartmentResource($this->department), and not DepartmentResource::minimalAttributes().

Why not? Because the behavior is so weird, only show the attributes from the first record and the others records disappear
14-4-2022 12 4 2 1

from json-api.

DiarQoroviqi avatar DiarQoroviqi commented on June 18, 2024

Hi @jonquintero did you find any solution for not showing the attributes of relation, because I have the same problem, it only shows the id and the type and an empty object of meta?

from json-api.

jonquintero avatar jonquintero commented on June 18, 2024

Hi @DiarQoroviqi, unfortunately I couldn't, I had to remove the package and use https://laravel.com/docs/9.x/eloquent-resources

from json-api.

timacdonald avatar timacdonald commented on June 18, 2024

Hey folks, I believe this is cause by the relationship being null and not a model. When your relation is nullable, you should follow this pattern...

return [
     'user' => fn () => optional($this->user, fn ($user) => new UserResource($user)),
];

This is documented: https://github.com/timacdonald/json-api#resource-relationships

Note: In an upcoming verison, this will be improved so you can just return the resource and not have to juggle it being null.

from json-api.

ArtMin96 avatar ArtMin96 commented on June 18, 2024

I have the same problem

Not working

public function toRelationships(Request $request): array
 {
    return [
        'services' => fn () => optional($this->services, fn ($services) => ServicesResource::collection($services)),
    ];
}

Not working

public function toRelationships(Request $request): array
 {
    return [
        'services' => fn () => ServicesResource::collection($services),
    ];
}

Not working

public $relationships = [
    'services' => ServicesResource::class,
];

Result
image

from json-api.

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.