Skip to content

Is it possible to map different resources to the same model #610

Open
@michaelklopf

Description

@michaelklopf

Hi,

I'm currently trying to resolve an issue I have with how the API is structured. We have two different kind of users that are appearing in relationships. I'm looking for a way to differentiate the two user groups with resources. Something like this

'resources' => [
    'employees' => \App\User::class,
    'consultants' => \App\User::class,
]
$api->resource('assignments')
  ->only('index', 'read', 'update')
  ->relationships(function ($relations) {
      $relations->hasOne('created-by', 'employees')->readOnly();
      $relations->hasOne('supported-by', 'consultants');
  }) //...

When querying the relationship /api/assignments/1/created-by I would like to receive the underlying user object as "type": "employees" and for /api/assignments/1/supported-by as "type": "consultants".

Employees and consultants have their own schemas and adapters, but for both resources I'm getting "type": "employees".

Is there a solution in this package, or do I need to make a new model class for the different user types?

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