Closed iwasherefirst2 closed 4 years ago
Fixed it. There were two things that I did wrong:
I actually misinterpreted the docs, even if you extend from Item
you have to use TypeMapperServiceProvider
(I thought its only necessery if one implements the interface and creates a custom item class).
I followed the instructions here and create for each item a type
in singular, however, in this backend tutorial the type
is in plural. You see above congress
is used in Item
but congresses
is used in API. I had to change it to congresses
in the item, now it works.
Hi @iwasherefirst2, good to hear you found it out! Indeed every custom item should be registered with the TypeMapper
and the type should correspond with the type used by the API.
Detailed description
I have one repository
CongressRepository
and two Items,CongressItem
&SpeakerItem
. ACongressItem
has manySpeakerItems
.If I fetch the children of
CongressRepository
, then they seem to be ofItem
class and not a class ofCongressItem
.I am not sure if this is a bug or if I am just not using it right.
The last command fails with this error message:
This also causes other issues, like if only the link of
speaker
is provided by the API, then$congress->speakers
is null.Context
This is the output when calling the api
/api/v1/congresses
:This is my
CongressItem
class:And my
CongressRepository
What I tried so far
I also tried to bind the
TypeMapperServiceProvider
and explicitly added the items there:but this didn't help either. Also, as far as I understood the docs, I don't have to do this step because I am extending the class from
Item
.Your environment
Using Laravel v6.4.1 on Ubuntu 18.04 with Homestead v9.4.0 & Vagrant 2.2.5. PHP Version is 7.3