Skip to content

Problem with countables relationships #271

Open
@IAndreaGiuseppe

Description

@IAndreaGiuseppe

Hi,

I'm following the docs https://laraveljsonapi.io/docs/3.0/digging-deeper/countable.html about countable relationships but seems to not having any results from it.

I have a complete set of json-api working in production so Im willing Im doing things right.
Now for a new FE I need to know before if a relation "exists", has more than 0 models. I found that countable relationships can do the trick so:

I have a ContainerSchema:

class ContainerSchema extends Schema
{
    /**
     * The model the schema corresponds to.
     *
     * @var string
     */
    public static string $model = Container::class;

    /**
     * Get the resource fields.
     *
     * @return array
     */
    public function fields(): array
    {
        return [
            ID::make(),
            Str::make('label'),
            // ...

            HasMany::make('rows')->canCount(),
        ];
    }
}

Now on the request side I can do this:

https://domain.com/v1/containers/115?withCount=rows

and should see the meta attribute within the rows relationship. But the response doesn't change at all, same response as before adding the ->canCount() method.

Im using : "laravel-json-api/laravel": "^3.2" any suggestions?

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions