Skip to content

[Q] Shouldn't be 'index' the route name for the listing action of a HasMany relationship? #233

@nelson6e65

Description

@nelson6e65

I have in my route:

# routes/api.php
$server
  ->resource('users', JsonApiController::class)
  ->relationships(function (Relationships $relations) {
      $relations->hasMany('user-organizations');
  });
# UserSchema.php
public function fields(): array
{
    return [
        // ...
        Relations\HasMany::make('user-organizations')->type('user-organizations'),
    ];
}

But the resulting route name is api.v1.users.user-organizations instead of api.v1.users.user-organizations.index:

 GET|HEAD  api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.show
 PATCH     api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.update
 POST      api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.attach
 DELETE    api/v1/users/{user}/relationships/user-organizations ... api.v1.users.user-organizations.detach
 GET|HEAD  api/v1/users/{user}/user-organizations ................. api.v1.users.user-organizations

Am I missing something, or it's OK?

How can I change it to have 'index' by default in all routes of this kind, instead of the "naked" route action?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions